1 #ifndef __creaImageIODicomDatabase_h_INCLUDED__
2 #define __creaImageIODicomDatabase_h_INCLUDED__
5 #include <creaImageIODicomNode.h>
6 #include <creaImageIOImageReader.h>
10 #include <wx/progdlg.h>
18 //=====================================================================
19 class DicomDatabase : public DicomNode
23 /// Creates a database associated to the file 'filename'.
24 /// Does not create the db nor reads any data from the file
25 DicomDatabase(const std::string& filename, int flags = 0);
29 /// Returns the DicomNodeTypeDescription for DicomNodes of type c
30 DicomNodeTypeDescription& GetDicomNodeTypeDescription(DicomNode::Type c)
31 { return mDicomNodeTypeDescription[c]; }
32 /// Returns the DicomNodeTypeDescription for DicomNodes of type c (const)
33 const DicomNodeTypeDescription& GetDicomNodeTypeDescription(DicomNode::Type c) const
34 { return mDicomNodeTypeDescription[c]; }
37 /// Returns the sqlite db file name
38 const std::string& GetFileName() const { return UnsafeGetFieldValue("File name"); }
39 void SetName(const std::string& n) { UnsafeSetFieldValue("Name",n); }
40 const std::string& GetName() const { return UnsafeGetFieldValue("Name"); }
46 //=============================================================
48 bool LocationIsValid();
49 /// Creates a new db on disk
51 /// Opens an existing db on disk
56 /// Recursively loads the children of node 'parent' until maxlevel
58 /// If parent == NULL or parent == this then starts with the 'children' of
59 /// the database itself, i.e. the patients.
60 /// Returns the total number of children loaded.
61 int DBLoadChildren(DicomNode* parent, DicomNode::Type maxlevel);
78 long update_structs_time;
79 long update_database_time;
81 bool cancelled_by_user;
93 update_structs_time(0),
94 update_database_time(0),
96 cancelled_by_user(false)
102 bool IsHandledFile( const std::string& filename);
103 bool AddFile( const std::string& filename,
104 UpdateSummary& summary );
105 bool AddFiles( const std::vector<std::string>& filename,
106 wxProgressDialog* progress,
107 UpdateSummary& summary);
108 bool AddDirectory( const std::string& directory,
110 wxProgressDialog* progress,
111 UpdateSummary& summary
114 void ParseDirectory( const std::string& directory,
115 std::vector<std::string> &Filenames,
117 wxProgressDialog* progress,
118 UpdateSummary& summary);
121 /// Removes the node and its descendants from the db
122 bool Remove(DicomNode*);
123 //=============================================================
126 int DBQueryNumberOfChildren(DicomNode* n);
131 void ImportDicomNodeTypeDescriptionsFromDB();
135 void BuildDefaultDicomNodeTypeDescriptions();
136 void AppendSQLFieldsDefinition(DicomNode::Type c, std::string& s);
137 void ExportDicomNodeTypeDescriptionsToDB();
141 bool DBStructureIsValid();
145 bool DBInsert(DicomNode* alien_node, UpdateSummary& summary);
148 std::string DBGetDicomNodeId(DicomNode* node, const std::string& parent_id);
149 DicomNode* GetDicomNodeFromTypeId(DicomNode::Type t, const std::string& id);
152 DicomNode* DBGetOrCreateDicomNode(DicomNode* alien_node,
153 DicomNode* internal_parent,
154 std::string parentid,
155 std::string& created_id,
156 UpdateSummary& summary);
158 DicomNode* DBGetOrCreateParent(DicomNode* alien_node,
159 std::string& parent_id,
160 UpdateSummary& summary);
162 void DBRecursiveGetOrCreateDicomNode(DicomNode* alien_node,
164 const std::string& parent_id,
165 UpdateSummary& summary);
169 void DBRecursiveRemoveDicomNode(DicomNode* node);
172 void BuildSQLFieldsValues(DicomNode* n,
176 DicomNode* GetChildrenLike(DicomNode* internal_parent,
177 DicomNode* alien_node);
188 bool operator< (const TypeId& o) const
190 return ((type<o.type) ||
191 ((type==o.type)&&id<o.id));
195 typedef std::map<TypeId,DicomNode*> TypeIdToDicomNodeMapType;
196 TypeIdToDicomNodeMapType mTypeIdToDicomNodeMap;
199 /// The 5 descriptions of node types (Database,Patient,Study,Series,Image)
200 /// The array is accessed through the DicomNode::TypeCode
201 DicomNodeTypeDescription mDicomNodeTypeDescription[5];
204 /// The physical location associated to the DicomDatabase (directory, db file...)
205 std::string mFileName;
213 }; // class DicomDatabase
214 //=====================================================================
218 } // namespace creaImageIO
222 #endif // #ifndef __creaImageIODicomDatabase_h_INCLUDED__