00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #ifndef _GDCMDICOMDIR_H_
00020 #define _GDCMDICOMDIR_H_
00021 
00022 #include "gdcmDocument.h"
00023 #include "gdcmDebug.h"
00024 
00025 #include <list>
00026 #include <vector>
00027 
00028 namespace GDCM_NAME_SPACE 
00029 {
00030 
00031 class DicomDirPatient;
00032 class DicomDirMeta;
00033 class DicomDirElement;
00034 class DicomDirStudy;
00035 class DicomDirSerie;
00036 class DicomDirVisit;
00037 class DicomDirImage;
00038 class DicomDirPrivate;
00039 class SQItem;
00040 
00041 typedef std::list<DicomDirPatient *> ListDicomDirPatient;
00042 typedef std::vector<Document *> VectDocument;
00043 
00044 
00056 class GDCM_EXPORT DicomDir: public Document
00057 {
00058    gdcmTypeMacro(DicomDir);
00059 
00060 public:
00062    static DicomDir *New() {return new DicomDir();}
00063 
00064 
00065    bool Load( );
00066    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
00067 
00069    void SetDirectoryName(std::string const &dirName)
00070         { ParseDir = true; if (Filename != dirName)
00071                                Filename = dirName, IsDocumentModified = true;}
00073    virtual void SetFileName(std::string const &fileName)
00074                    { ParseDir = false; if (Filename != fileName)
00075                               Filename = fileName, IsDocumentModified = true;}
00076 
00077    
00078    virtual bool IsReadable();
00079 
00080    
00081    DicomDirMeta *NewMeta();
00083    DicomDirMeta *GetMeta() { return MetaElems; }
00084 
00085    
00086    DicomDirPatient *NewPatient();
00087    void ClearPatient();
00088 
00089    DicomDirPatient *GetFirstPatient();
00090    DicomDirPatient *GetNextPatient();
00092    int              GetNumberOfPatients() { return Patients.size();}
00093    
00094    
00095    void ParseDirectory();
00096 
00098    float GetProgress() const { return Progress; }
00100    void  AbortProgress() { Abort = true; }
00102    bool  IsAborted() { return Abort; }
00103 
00104    
00105    bool Write(std::string const &fileName);
00106 
00107    bool Anonymize();
00108 
00109    virtual void Copy(DocEntrySet *set);
00110 
00112    typedef enum
00113    {
00114       GDCM_DICOMDIR_NONE,
00115       GDCM_DICOMDIR_META,
00116       GDCM_DICOMDIR_PATIENT,
00117       GDCM_DICOMDIR_STUDY,
00118       GDCM_DICOMDIR_SERIE,
00119       GDCM_DICOMDIR_VISIT,
00120       GDCM_DICOMDIR_IMAGE,
00121       GDCM_DICOMDIR_PRIVATE
00122    } DicomDirType;
00123 
00124 protected:
00125    DicomDir();
00126    ~DicomDir();
00127 
00128 
00129    void CreateDicomDirChainedList(std::string const &path);
00130 
00131 private:
00132    void Initialize();
00133    void CreateDicomDir();
00134    bool DoTheLoadingJob();
00135    bool AddPatientToEnd(DicomDirPatient *dd);   
00136    bool AddStudyToEnd  (DicomDirStudy   *dd);
00137    bool AddSerieToEnd  (DicomDirSerie   *dd);
00138    bool AddVisitToEnd  (DicomDirVisit   *dd);
00139    bool AddImageToEnd  (DicomDirImage   *dd);
00140    bool AddPrivateToEnd(DicomDirPrivate *dd);
00141    
00142    void SetElements(std::string const &path, VectDocument const &list);
00143    void SetElement (std::string const &path, DicomDirType type,
00144                     Document *header);
00145    void MoveSQItem(DocEntrySet *dst, DocEntrySet *src);
00146 
00147    static bool HeaderLessThan(Document *header1, Document *header2);
00148 
00149 
00150 
00152    DicomDirMeta *MetaElems;
00153 
00155    ListDicomDirPatient Patients;
00156    ListDicomDirPatient::iterator ItPatient;
00157 
00159    bool ParseDir;
00160 
00161 };
00162 } 
00163 
00164 #endif