CONDITION DDR_GetStudyList(DCM_OBJECT ** object, const char *patientID, LST_HEAD ** lst) { LST_HEAD *patientList; DDR_PATIENT *pPtr; CONDITION cond; U32 offset; DCM_OBJECT *studyObject; /* * Create a patient list and get all of the patients in the DICOMDIR * object */ patientList = LST_Create(); cond = DDR_GetPatientList(object, &patientList); pPtr = LST_Dequeue(&patientList); /* * Scan through the patient list for a patient whose patient ID matches * that passed * by the caller. When we find that, walk through the * study list for that patient * and fill the caller's list with * DDR_STUDY records. */ while (pPtr != NULL) { if (strcmp(pPtr->PatientID, patientID) == 0) { offset = pPtr->StudyLinkOffset; while (offset != 0) { cond = DCM_GetSequenceByOffset(object, DCM_DIRRECORDSEQUENCE, offset, &studyObject); if (cond != DCM_NORMAL) { exit(1); /* repair */ } addStudyRecord(&studyObject, lst); offset = offsetNextRecord(&studyObject); } } free(pPtr); pPtr = LST_Dequeue(&patientList); } LST_Destroy(&patientList); return DDR_NORMAL; }
static void localDirectory(llist entries) { LST_HEAD *patientList; DCM_OBJECT *dirFile; DDR_PATIENT *patientNode; CONDITION cond; cond = DCM_OpenFile("/tmp/dicomdir", DCM_ORDERLITTLEENDIAN | DCM_PART10FILE, &dirFile); patientList = LST_Create(); cond = DDR_GetPatientList(&dirFile, &patientList); html_header(); html_begin_body_options("DICOM Patient Search", "bgcolor=#ffffff"); printf("Please select one patient to see a list of studies<p>\n"); printf("<form method=GET action=""/cgi-bin/acc_agent.cgi"">\n"); patientNode = LST_Dequeue(&patientList); printf("<select name=patientID size=10>\n"); while(patientNode != NULL) { printf("<option value=""%s"">%s %s %s\n", patientNode->PatientID, patientNode->PatientID, patientNode->PatientName, patientNode->BirthDate); free(patientNode); patientNode = LST_Dequeue(&patientList); } printf("</select>\n"); printf("<br>\n"); printf("<input type=submit value=""LocalPatientSelect"" name=submitSearch>\n"); printf("<input type=submit value=""Retrieve All Studies from Archive"" name=submitSearch>\n"); printf("</form>\n"); html_end(); LST_Destroy(&patientList); DCM_CloseObject(&dirFile); }
CONDITION DDR_GetSeriesLeafList(DCM_OBJECT ** object, const char *patientID, const char *studyInstanceUID, const char *seriesInstanceUID, LST_HEAD ** leafList) { LST_HEAD *seriesList; DDR_SERIES *sPtr; CONDITION cond; U32 offset; DCM_OBJECT *leafObject; seriesList = LST_Create(); cond = DDR_GetSeriesList(object, patientID, studyInstanceUID, &seriesList); if (cond != DDR_NORMAL) return cond; sPtr = LST_Dequeue(&seriesList); while (sPtr != NULL) { if (strcmp(sPtr->SeriesInstanceUID, seriesInstanceUID) == 0) { offset = sPtr->LeafLinkOffset; while (offset != 0) { cond = DCM_GetSequenceByOffset(object, DCM_DIRRECORDSEQUENCE, offset, &leafObject); if (cond != DCM_NORMAL) { return DDR_ERROR; } addLeafRecord(&leafObject, leafList); offset = offsetNextRecord(&leafObject); } } free(sPtr); sPtr = LST_Dequeue(&seriesList); } LST_Destroy(&seriesList); return DDR_NORMAL; }
static CONDITION studyComponentSet(MSG_N_SET_REQ * request, MSG_N_SET_RESP * response, CALLBACK_CTX * ctx) { CONDITION cond; FIS_STUDYCOMPONENTRECORD sc; long flag; FIS_SCSERIESRECORD *series; FIS_SCIMAGERECORD *image; response->status = MSG_K_SUCCESS; if (request->dataSetType != DCM_CMDDATANULL) { (void) DCM_DumpElements(&request->dataSet, 0); } else { response->status = MSG_K_MISSINGATTRIBUTE; goto ExitPoint; } cond = FIS_ParseObject(&request->dataSet, FIS_K_STUDYCOMPONENT, &sc); if (cond != FIS_NORMAL) { response->status = MSG_K_PROCESSINGFAILURE; goto ExitPoint; } sc.Flag &= STUDYCOMPONENT_SET_FLAGS; if (sc.Flag == 0) goto ExitPoint; strcpy(sc.StuComUID, request->instanceUID); sc.Flag |= FIS_K_STUDYCOMP_STUCOMUID; cond = FIS_Update(ctx->fis, FIS_K_STUDYCOMPONENT, &sc); if (cond != FIS_NORMAL) { response->status = MSG_K_PROCESSINGFAILURE; goto ExitPoint; } if (sc.Flag & FIS_K_STUDYCOMP_SERIESLIST) { /* Delete existing values in series/image tables and insert new values */ cond = FIS_Delete(ctx->fis, FIS_K_SCSERIES, FIS_K_STUDYCOMPONENT, request->instanceUID); if (cond != FIS_NORMAL) { response->status = MSG_K_PROCESSINGFAILURE; goto ExitPoint; } cond = FIS_Delete(ctx->fis, FIS_K_SCIMAGE, FIS_K_STUDYCOMPONENT, request->instanceUID); if (cond != FIS_NORMAL) { response->status = MSG_K_PROCESSINGFAILURE; goto ExitPoint; } while ((series = LST_Dequeue(&sc.SeriesList)) != NULL) { strcpy(series->StuComUID, sc.StuComUID); series->Flag |= FIS_K_SCSERIES_STUCOMUID; cond = FIS_Insert(ctx->fis, FIS_K_SCSERIES, series); if (cond != FIS_NORMAL) { response->status = MSG_K_PROCESSINGFAILURE; COND_DumpConditions(); goto ExitPoint; } while ((image = LST_Dequeue(&series->ImageList)) != NULL) { strcpy(image->SerInsUID, series->SerInsUID); strcpy(image->StuComUID, series->StuComUID); image->Flag |= FIS_K_SCIMAGE_SERINSUID | FIS_K_SCIMAGE_STUCOMUID; cond = FIS_Insert(ctx->fis, FIS_K_SCIMAGE, image); if (cond != FIS_NORMAL) { response->status = MSG_K_PROCESSINGFAILURE; COND_DumpConditions(); goto ExitPoint; } free(image); } (void) LST_Destroy(&series->ImageList); free(series); } (void) LST_Destroy(&sc.SeriesList); } response->dataSetType = DCM_CMDDATANULL; strcpy(response->classUID, request->classUID); strcpy(response->instanceUID, request->instanceUID); response->conditionalFields = MSG_K_N_SETRESP_REQUESTEDCLASSUID | MSG_K_N_SETRESP_REQUESTEDINSTANCEUID; ExitPoint: COND_DumpConditions(); return 1; }
static void selectSeries(llist entries) { CONDITION cond; char dbKey[64]; char studyUID[65]; char seriesUID[65]; IDB_Query series; QUERY_LIST_ITEM *item; IDB_InstanceListElement *instancePtr; unsigned long byteCount = 0; char password[64]; DMAN_HANDLE *controlHandle; LST_HEAD *destinationList; openCTN(&controlHandle); strcpy(dbKey, cgi_val(entries, "DBKey")); strcpy(studyUID, cgi_val(entries, "StudyUID")); strcpy(seriesUID, cgi_val(entries, "SeriesUID")); strcpy(password, cgi_val(entries, "password")); TBL_SetOption("OPEN_SPEEDUP"); cond = searchOneSeries(dbKey, studyUID, seriesUID, &series); html_header(); html_begin_body_options("CTN Archive: Series Management", "bgcolor=#ffffff"); printf("<table>\n"); printf("<TR><TH align=right>Name: <TH align=left>%s</TR>\n", series.patient.PatNam); printf("<TR><TH align=right>Date of Birth: <TH align=left>%s</TR>\n", series.patient.PatBirDat); printf("<TR><TH align=right>Series Number: <TH align=left>%s</TR>\n", series.series.SerNum); printf("<TR><TH align=right>Image Count: <TH align=left>%d</TR>\n", series.series.NumSerRelIma); printf("</table>\n"); printf("<form method=GET action=""archive_agent.cgi"">\n"); printf("<input type=hidden name=DBKey value=%s>\n", dbKey); printf("<input type=hidden name=StudyUID value=%s>\n", studyUID); printf("<input type=hidden name=SeriesUID value=%s>\n", seriesUID); printf("<input type=hidden name=password value=%s>\n", password); { DMAN_VIDEOIMAGEDEST *video; destinationList = LST_Create(); cond = listOfDestinations(&controlHandle, destinationList); printf("<select name=DestinationApplication size=10>\n"); video = LST_Dequeue(&destinationList); while (video != NULL) { /*char tmp[1024];*/ DMAN_APPLICATIONENTITY ae; memset(&ae, 0, sizeof(ae)); ae.Type = DMAN_K_APPLICATIONENTITY; DMAN_LookupApplication(&controlHandle, video->RespondingTitle, &ae); /*sprintf(tmp, "%17s %s", ae.Title, ae.Title, ae.Node, ae.Comment);*/ printf("<option value=""%s"">%16s %15s %d %s\n", /* ae.Title,*/ video->RespondingTitle, ae.Title, ae.Node, ae.Port, ae.Comment); free(video); video = LST_Dequeue(&destinationList); } printf("</select>\n"); } LST_Destroy(&destinationList); printf("<br>\n"); printf("<input type=submit value=""MoveSeries"" name=submitSearch>\n"); printf("</form>\n"); html_end(); }
static void selectArchive(llist entries) { CONDITION cond; LST_HEAD *studyList; char dbKey[64]; QUERY_LIST_ITEM *item; IDB_Limits limits; char password[64]; int flag = 0; studyList = LST_Create(); strcpy(dbKey, cgi_val(entries, "DBKey")); strcpy(password, cgi_val(entries, "password")); TBL_SetOption("OPEN_SPEEDUP"); cond = listOfStudies(dbKey, studyList); orderStudyListByName(studyList); flag = passwordCompare(dbKey, password); if (flag == 0) strcpy(password, "READONLY"); memset(&limits, 0, sizeof(limits)); cond = dbLimits(dbKey, &limits); html_header(); html_begin_body_options("CTN Archive: List of Studies", "bgcolor=#ffffff"); if (flag == 0) { printf("Read only access granted <br>\n"); } printf("CTN Archive: %s <br> \n", dbKey); { char *remoteUser; remoteUser = getenv("REMOTE_USER"); if (remoteUser == NULL) remoteUser = "******"; printf("Remote user: %s<br>\n", remoteUser); } printf("%d patients, %d studies, %d images <br>\n", limits.PatientCount, limits.StudyCount, limits.ImageCount); printf("DB Size/Limits (MB): %d/%d<br>\n", limits.DBSize/1000000, limits.DBLimit); #if 0 printf("%d studies <br><br>\n", LST_Count(&studyList)); #endif printf("<pre>\n"); item = LST_Dequeue(&studyList); while(item != NULL) { char tmp[1024]; sprintf(tmp, "%-30s %8s (%2d series) %-32s", item->query.patient.PatNam, item->query.study.StuDat, item->query.study.NumStuRelSer, item->query.study.StuDes); #if 0 printf("<a href=""/cgi-bin/archive_agent.cgi?submitSearch=%s&DBKey=%s&StudyUID=%s"">%s</a><br>\n", #endif printf( "<a href=""/cgi-bin/archive_agent.cgi?submitSearch=%s&DBKey=%s&\ password=%s&StudyUID=%s"">%s</a>\n", "StudySelect", dbKey, password, item->query.study.StuInsUID, tmp); free(item); item = LST_Dequeue(&studyList); } printf("</pre>\n"); LST_Destroy(&studyList); html_end(); }
/* exitApplication ** ** Purpose: ** Exit the application in presence of some errors. Before exiting, ** free all the handles which were allocated to the application ** ** Parameter Dictionary: ** cond The condition that caused the app to exit ** ** Return Values: ** None ** ** Notes: ** ** Algorithm: ** Description of the algorithm (optional) and any other notes. */ void exitApplication(CONDITION cond) { CONDITION rtnCond; fprintf(stderr, "Freeing all handles\n"); /* free all handles here */ #ifdef ASG if (appHandles.gqID != -1) { rtnCond = kill_queue(appHandles.gqID); if (CTN_ERROR(rtnCond)) { fprintf(stderr, "APP Error freeing generalized queue\n"); COND_DumpConditions(); } } #endif if (appHandles.network) { rtnCond = DUL_DropNetwork(&appHandles.network); if (CTN_ERROR(rtnCond)) { fprintf(stderr, "APP Error freeing network key\n"); COND_DumpConditions(); } } if (appHandles.association) { rtnCond = DUL_DropAssociation(&appHandles.association); if (CTN_ERROR(rtnCond)) { fprintf(stderr, "APP Error freeing association key\n"); COND_DumpConditions(); } } if (appHandles.service) { rtnCond = DUL_ClearServiceParameters(appHandles.service); if (CTN_ERROR(rtnCond)) { fprintf(stderr, "APP Error clearing service parameters\n"); COND_DumpConditions(); } } if (appHandles.processList) { PROCESS_ELEMENT * e = NULL; e = LST_Head(&appHandles.processList); if (e != NULL) (void) LST_Position(&appHandles.processList, e); while (e != NULL) { free(e); e = LST_Dequeue(&appHandles.processList); } rtnCond = LST_Destroy(&appHandles.processList); if (CTN_ERROR(rtnCond)) { fprintf(stderr, "APP Error freeing Process List\n"); COND_DumpConditions(); } } /* Now the final exit */ if (CTN_ERROR(cond)) { fprintf(stderr, "\n\n"); fprintf(stderr, "APP Abnormal Exit\n"); COND_DumpConditions(); fprintf(stderr, "\n\n"); exit(1); /* error exit status */ } fprintf(stderr, "\n\n"); exit(0); /* normal exit */ }