Пример #1
0
CONDITION
IAP_InstanceArraytoElement(char *SOPArray, size_t SOPSpacing,
	      char *UIDArray, size_t UIDSpacing, int count, DCM_ELEMENT * e)
{
    CONDITION
	cond;
    DCM_ELEMENT
	classElement = {
	DCM_IDREFERENCEDSOPCLASSUID, DCM_UI, "", 1, 0, NULL
    },
	uidElement = {
	DCM_IDREFERENCEDSOPINSTUID, DCM_UI, "", 1, 0, NULL
    };
    DCM_OBJECT
	* object;
    DCM_SEQUENCE_ITEM
	* item;

    e->d.sq = LST_Create();
    if (e->d.sq == NULL)
	return 0;		/* repair */

    while (count-- > 0) {
	item = malloc(sizeof(*item));
	if (item == NULL)
	    return 0;		/* repair */
	cond = DCM_CreateObject(&item->object);
	if (cond != DCM_NORMAL)
	    return 0;		/* repair */
	classElement.d.string = SOPArray;
	classElement.length = strlen(SOPArray);
	cond = DCM_AddElement(&item->object, &classElement);
	if (cond != DCM_NORMAL)
	    return 0;		/* repair */
	uidElement.d.string = UIDArray;
	uidElement.length = strlen(UIDArray);
	cond = DCM_AddElement(&item->object, &uidElement);
	if (cond != DCM_NORMAL)
	    return 0;		/* repair */

	cond = LST_Enqueue(&e->d.sq, item);
	if (cond != LST_NORMAL)
	    return 0;		/* repair */

	SOPArray += SOPSpacing;
	UIDArray += UIDSpacing;
    }
    return HAP_NORMAL;
}
Пример #2
0
DCM_OBJECT *
createQueryObject(const char *fileName)
{
    DCM_OBJECT *obj;
    CONDITION cond;
    DCM_ELEMENT e;
    char txt[1024] = "";

    int group = 0;
    int element = 0;
    char textValue[1024];

    if (fileName != NULL) {
	cond = DCM_OpenFile(fileName, DCM_ORDERLITTLEENDIAN, &obj);
	if (cond != DCM_NORMAL) {
	    COND_DumpConditions();
	    exit(1);
	}
	return obj;
    }
    cond = DCM_CreateObject(&obj, 0);
    if (cond != DCM_NORMAL) {
	COND_DumpConditions();
	exit(1);
    }
    while (fgets(txt, sizeof(txt), stdin) != NULL) {
	if (txt[0] == '#' || txt[0] == '\0')
	    continue;
	if (txt[0] == '\n' || txt[0] == '\r')
	    continue;

	if (sscanf(txt, "%x %x %[^\n]", &group, &element, textValue) != 3)
	    continue;

	e.tag = DCM_MAKETAG(group, element);
	DCM_LookupElement(&e);
	if (strncmp(textValue, "#", 1) == 0) {
	    e.length = 0;
	    e.d.string = NULL;
	} else {
	    e.length = strlen(textValue);
	    e.d.string = textValue;
	}

	cond = DCM_AddElement(&obj, &e);
	if (cond != DCM_NORMAL) {
	    COND_DumpConditions();
	    exit(1);
	}
    }

    return obj;
}
Пример #3
0
CONDITION
HAP_NormalizedToObject(DCM_OBJECT ** object,
		       HAP_ELEMENT_MAP * map, int size)
{
    int
        index,
        temp;
    CONDITION
	cond;
    DCM_ELEMENT
	e;

    for (index = 0; index < size; index++)
	if ((*map[index].flagAddress & map[index].flag) != 0) {
	    e = map[index].e;
	    if (DCM_IsString(e.representation))
		e.length = strlen(e.d.string);
	    cond = DCM_AddElement(object, &e);
	    if (cond != DCM_NORMAL)
		return HAP_ILLEGALOBJECT;
	}
    return HAP_NORMAL;
}
Пример #4
0
int
r_buildSequence(DCM_OBJECT ** object, SQ_TYPE type)
{

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

    static SQ_MAP_SOP sops[] = {
	{SQ_K_REFINTERPRETATIONSOPINSTANCEUID,
	    DICOM_SOPCLASSDETACHEDINTERPRETMGMT, &(p.RISequenceCount),
	sizeof(SQ_REFINTERPRETATIONSOPINSTANCEUID)},
	{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_REFINTERPRETATIONSOPINSTANCEUID:
	    interp = (SQ_REFINTERPRETATIONSOPINSTANCEUID *) pointer;
	    interp->type = SQ_K_REFINTERPRETATIONSOPINSTANCEUID;
	    sprintf(interp->referencedSOPClassUID, "%s", sops[i].sopclass);
	    sprintf(interp->referencedSOPInstanceUID, "%s",
		    p.RISequence[index]);
	    break;
	case SQ_K_REFSTUDYSOPINSTANCEUID:
	    study = (SQ_REFSTUDYSOPINSTANCEUID *) pointer;
	    study->type = SQ_K_REFSTUDYSOPINSTANCEUID;
	    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_SOPCLASSDETACHEDINTERPRETMGMT, sopclass)) {
	while (index < p.RISequenceCount) {
	    interp = malloc(sizeof(*interp));
	    if (interp == NULL)
		return -1;
	    interp->type = SQ_K_REFINTERPRETATIONSOPINSTANCEUID;
	    sprintf(interp->referencedSOPClassUID, "%s", sopclass);
	    sprintf(interp->referencedSOPInstanceUID, "%s",
		    p.RISequence[index]);
	    LST_Enqueue(&l, interp);
	    index++;
	}

	cond = SQ_BuildSequence(&l, SQ_K_REFINTERPRETATIONSOPINSTANCEUID, &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_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;
    }
*/
}
Пример #5
0
int
v_buildSequence(DCM_OBJECT ** object, SQ_TYPE type)
{

    int index = 0;
    int i;
    LST_HEAD *l;
    DCM_ELEMENT *e;
    CONDITION cond;
    SQ_REFPATIENTSOPINSTANCEUID *patient;
    SQ_REFSTUDYSOPINSTANCEUID *study;
    SQ_REQPROCEDURECODE *code;
    void *pointer;

    static SQ_MAP_SOP sops[] = {
	{SQ_K_REFPATIENTSOPINSTANCEUID,
	    DICOM_SOPCLASSDETACHEDPATIENTMGMT, &(p.RPSequenceCount),
	sizeof(SQ_REFPATIENTSOPINSTANCEUID)},
	{SQ_K_REFSTUDYSOPINSTANCEUID,
	    DICOM_SOPCLASSDETACHEDSTUDYMGMT, &(p.RSSequenceCount),
	sizeof(SQ_REFSTUDYSOPINSTANCEUID)},
	{SQ_K_ADMITDIAGNOSISCODE,
	    "", &(p.ADCSequenceCount),
	sizeof(SQ_REQPROCEDURECODE)},
	{SQ_K_DISCHARGEDIAGNOSISCODE,
	    "", &(p.DDCSequenceCount),
	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_REFPATIENTSOPINSTANCEUID:
	    patient = (SQ_REFPATIENTSOPINSTANCEUID *) pointer;
	    patient->type = type;
	    sprintf(patient->referencedSOPClassUID, "%s", sops[i].sopclass);
	    sprintf(patient->referencedSOPInstanceUID, "%s",
		    p.RPSequence[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;
	case SQ_K_ADMITDIAGNOSISCODE:
	    code = (SQ_REQPROCEDURECODE *) pointer;
	    code->type = type;
	    strcpy(code->codeValue, p.ADCSequence[index].CodeValue);
	    strcpy(code->codingSchemeDesignator,
		   p.ADCSequence[index].CodingSchemeDesignator);
	    strcpy(code->codeMeaning, p.ADCSequence[index].CodeMeaning);
	    break;
	case SQ_K_DISCHARGEDIAGNOSISCODE:
	    code = (SQ_REQPROCEDURECODE *) pointer;
	    code->type = type;
	    strcpy(code->codeValue, p.DDCSequence[index].CodeValue);
	    strcpy(code->codingSchemeDesignator,
		   p.DDCSequence[index].CodingSchemeDesignator);
	    strcpy(code->codeMeaning, p.DDCSequence[index].CodeMeaning);
	    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 (type == REFPATIENTSQ) {
	while (index < p.RPSequenceCount) {
	    patient = malloc(sizeof(*patient));
	    if (patient == NULL)
		return -1;
	    patient->type = SQ_K_REFPATIENTSOPINSTANCEUID;
	    sprintf(patient->referencedSOPClassUID, "%s", DICOM_SOPCLASSDETACHEDPATIENTMGMT);
	    sprintf(patient->referencedSOPInstanceUID, "%s",
		    p.RPSequence[index]);
	    LST_Enqueue(&l, patient);
	    index++;
	}

	cond = SQ_BuildSequence(&l, SQ_K_REFPATIENTSOPINSTANCEUID, &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 (type == REFSTUDYSQ) {
	while (index < p.RSSequenceCount) {
	    study = malloc(sizeof(*study));
	    if (study == NULL)
		return -1;
	    study->type = SQ_K_REFSTUDYSOPINSTANCEUID;
	    sprintf(study->referencedSOPClassUID, "%s", DICOM_SOPCLASSDETACHEDSTUDYMGMT);
	    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;
    }
*/
}
Пример #6
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;
}
Пример #7
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;
}