00001 /* 00002 * 00003 * Copyright (C) 1993-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: dcmqrdb 00015 * 00016 * Author: Andrew Hewett, Marco Eichelberg 00017 * 00018 * Purpose: class DcmQueryRetrieveIndexDatabaseHandle 00019 * 00020 * Last Update: $Author: joergr $ 00021 * Update Date: $Date: 2010-10-14 13:16:41 $ 00022 * CVS/RCS Revision: $Revision: 1.8 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 00026 * 00027 */ 00028 00029 #ifndef DCMQRDBI_H 00030 #define DCMQRDBI_H 00031 00032 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 00033 #include "dcmtk/dcmqrdb/dcmqrdba.h" /* for class DcmQueryRetrieveDatabaseHandle */ 00034 00035 #include "dcmtk/dcmnet/dicom.h" 00036 #include "dcmtk/dcmnet/dimse.h" 00037 #include "dcmtk/ofstd/offname.h" 00038 00039 struct StudyDescRecord; 00040 struct DB_Private_Handle; 00041 struct DB_SmallDcmElmt; 00042 struct IdxRecord; 00043 struct DB_ElementList; 00044 class DcmQueryRetrieveConfig; 00045 00046 #define DBINDEXFILE "index.dat" 00047 00048 #ifndef _WIN32 00049 /* we lock image files on all platforms except Win32 where it does not work 00050 * due to the different semantics of LockFile/LockFileEx compared to flock. 00051 */ 00052 #define LOCK_IMAGE_FILES 00053 #endif 00054 00057 enum DB_LEVEL 00058 { 00060 PATIENT_LEVEL, 00062 STUDY_LEVEL, 00064 SERIE_LEVEL, 00066 IMAGE_LEVEL 00067 }; 00068 00076 enum DVIFhierarchyStatus 00077 { 00079 DVIF_objectIsNotNew, 00081 DVIF_objectIsNew, 00083 DVIF_objectContainsNewSubobjects 00084 }; 00085 00087 #define DB_UpperMaxStudies 500 00088 00090 #define DB_UpperMaxBytesPerStudy 0x40000000L 00091 00092 00097 class DcmQueryRetrieveIndexDatabaseHandle: public DcmQueryRetrieveDatabaseHandle 00098 { 00099 public: 00100 00110 DcmQueryRetrieveIndexDatabaseHandle( 00111 const char *storageArea, 00112 long maxStudiesPerStorageArea, 00113 long maxBytesPerStudy, 00114 OFCondition& result); 00115 00120 ~DcmQueryRetrieveIndexDatabaseHandle(); 00121 00127 void setIdentifierChecking(OFBool checkFind, OFBool checkMove); 00128 00138 OFCondition makeNewStoreFileName( 00139 const char *SOPClassUID, 00140 const char *SOPInstanceUID, 00141 char *newImageFileName); 00142 00154 OFCondition storeRequest( 00155 const char *SOPClassUID, 00156 const char *SOPInstanceUID, 00157 const char *imageFileName, 00158 DcmQueryRetrieveDatabaseStatus *status, 00159 OFBool isNew = OFTrue ); 00160 00174 OFCondition startFindRequest( 00175 const char *SOPClassUID, 00176 DcmDataset *findRequestIdentifiers, 00177 DcmQueryRetrieveDatabaseStatus *status); 00178 00190 OFCondition nextFindResponse( 00191 DcmDataset **findResponseIdentifiers, 00192 DcmQueryRetrieveDatabaseStatus *status); 00193 00200 OFCondition cancelFindRequest(DcmQueryRetrieveDatabaseStatus *status); 00201 00215 OFCondition startMoveRequest( 00216 const char *SOPClassUID, 00217 DcmDataset *moveRequestIdentifiers, 00218 DcmQueryRetrieveDatabaseStatus *status); 00219 00239 OFCondition nextMoveResponse( 00240 char *SOPClassUID, 00241 char *SOPInstanceUID, 00242 char *imageFileName, 00243 unsigned short *numberOfRemainingSubOperations, 00244 DcmQueryRetrieveDatabaseStatus *status); 00245 00252 OFCondition cancelMoveRequest(DcmQueryRetrieveDatabaseStatus *status); 00253 00257 OFCondition pruneInvalidRecords(); 00258 00259 // methods not inherited from the base class 00260 00264 void enableQuotaSystem(OFBool enable); 00265 00269 static void printIndexFile (char *storeArea); 00270 00276 OFCondition deleteImageFile(char* imgFile); 00277 00282 OFCondition DB_lock(OFBool exclusive); 00283 00286 OFCondition DB_unlock(); 00287 00293 OFCondition DB_IdxGetNext(int *idx, IdxRecord *idxRec); 00294 00299 OFCondition DB_IdxInitLoop(int *idx); 00300 00306 OFCondition DB_IdxRead(int idx, IdxRecord *idxRec); 00307 00312 OFCondition DB_GetStudyDesc(StudyDescRecord *pStudyDesc); 00313 00318 OFCondition DB_StudyDescChange(StudyDescRecord *pStudyDesc); 00319 00324 OFCondition DB_IdxRemove(int idx); 00325 00330 OFCondition instanceReviewed(int idx); 00331 00333 const char *getStorageArea() const; 00334 00336 const char *getIndexFilename() const; 00337 00338 00339 private: 00340 00341 OFCondition removeDuplicateImage( 00342 const char *SOPInstanceUID, const char *StudyInstanceUID, 00343 StudyDescRecord *pStudyDesc, const char *newImageFileName); 00344 int deleteOldestStudy(StudyDescRecord *pStudyDesc); 00345 OFCondition deleteOldestImages(StudyDescRecord *pStudyDesc, int StudyNum, char *StudyUID, long RequiredSize); 00346 int matchDate (DB_SmallDcmElmt *mod, DB_SmallDcmElmt *elt); 00347 int matchTime (DB_SmallDcmElmt *mod, DB_SmallDcmElmt *elt); 00348 int matchUID (DB_SmallDcmElmt *mod, DB_SmallDcmElmt *elt); 00349 int matchStrings (DB_SmallDcmElmt *mod, DB_SmallDcmElmt *elt); 00350 int matchOther (DB_SmallDcmElmt *mod, DB_SmallDcmElmt *elt); 00351 int dbmatch (DB_SmallDcmElmt *mod, DB_SmallDcmElmt *elt); 00352 void makeResponseList(DB_Private_Handle *phandle, IdxRecord *idxRec); 00353 int matchStudyUIDInStudyDesc (StudyDescRecord *pStudyDesc, char *StudyUID, int maxStudiesAllowed); 00354 OFCondition checkupinStudyDesc(StudyDescRecord *pStudyDesc, char *StudyUID, long imageSize); 00355 00356 OFCondition hierarchicalCompare ( 00357 DB_Private_Handle *phandle, 00358 IdxRecord *idxRec, 00359 DB_LEVEL level, 00360 DB_LEVEL infLevel, 00361 int *match); 00362 00363 OFCondition testFindRequestList ( 00364 DB_ElementList *findRequestList, 00365 DB_LEVEL queryLevel, 00366 DB_LEVEL infLevel, 00367 DB_LEVEL lowestLevel); 00368 00369 OFCondition testMoveRequestList ( 00370 DB_ElementList *findRequestList, 00371 DB_LEVEL queryLevel, 00372 DB_LEVEL infLevel, 00373 DB_LEVEL lowestLevel); 00374 00376 DB_Private_Handle *handle_; 00377 00379 OFBool quotaSystemEnabled; 00380 00382 OFBool doCheckFindIdentifier; 00383 00385 OFBool doCheckMoveIdentifier; 00386 00388 OFFilenameCreator fnamecreator; 00389 00390 }; 00391 00392 00396 class DcmQueryRetrieveIndexDatabaseHandleFactory: public DcmQueryRetrieveDatabaseHandleFactory 00397 { 00398 public: 00399 00403 DcmQueryRetrieveIndexDatabaseHandleFactory(const DcmQueryRetrieveConfig *config); 00404 00406 virtual ~DcmQueryRetrieveIndexDatabaseHandleFactory(); 00407 00416 virtual DcmQueryRetrieveDatabaseHandle *createDBHandle( 00417 const char *callingAETitle, 00418 const char *calledAETitle, 00419 OFCondition& result) const; 00420 00421 private: 00422 00424 const DcmQueryRetrieveConfig *config_; 00425 }; 00426 00427 #endif 00428 00429 /* 00430 * CVS Log 00431 * $Log: dcmqrdbi.h,v $ 00432 * Revision 1.8 2010-10-14 13:16:41 joergr 00433 * Updated copyright header. Added reference to COPYRIGHT file. 00434 * 00435 * Revision 1.7 2009-11-24 10:10:42 uli 00436 * Switched to logging mechanism provided by the "new" oflog module. 00437 * 00438 * Revision 1.6 2009-08-21 09:50:07 joergr 00439 * Replaced tabs by spaces and updated copyright date. 00440 * 00441 * Revision 1.5 2008-04-15 15:43:37 meichel 00442 * Fixed endless recursion bug in the index file handling code when 00443 * the index file does not exist 00444 * 00445 * Revision 1.4 2005/12/08 16:04:22 meichel 00446 * Changed include path schema for all DCMTK header files 00447 * 00448 * Revision 1.3 2005/04/22 15:36:34 meichel 00449 * Passing calling aetitle to DcmQueryRetrieveDatabaseHandleFactory::createDBHandle 00450 * to allow configuration retrieval based on calling aetitle. 00451 * 00452 * Revision 1.2 2005/04/04 10:04:45 meichel 00453 * Added public declarations for index file functions that are 00454 * used from module dcmpstat 00455 * 00456 * Revision 1.1 2005/03/30 13:34:50 meichel 00457 * Initial release of module dcmqrdb that will replace module imagectn. 00458 * It provides a clear interface between the Q/R DICOM front-end and the 00459 * database back-end. The imagectn code has been re-factored into a minimal 00460 * class structure. 00461 * 00462 * 00463 */