Skip to content
David Sarrut edited this page May 28, 2015 · 23 revisions

Simplified API.


Core

In the following code, we omit the namespace, use:

using namespace syd;

Database manager

Get instance:

DatabaseManager * m = DatabaseManager::GetInstance();
auto & list = m->GetDatabaseSchemas();

Create a database:

Database * db = m->Create("StandardDatabase", dbname, folder);

Read a database:

Database * db = m->Read(dbname);
StandardDatabase * db = m->Read<StandardDatabase>(dbname);

Functions common to all databases

Get information:

std::string s = db->GetDatabaseSchema();   // Name of the sql schema, i.e. "StandardDatabase"
std::string s = db->GetFilename();         // Filename i.e. test.db
std::string s = db->GetDBFolder();         // Image folder of the db, relative to the test.db folder
std::string s = db->GetAbsoluteDBFolder(); // Image folder (absolute path)

Basics operations are 'CRUD': Create, Read, Update and Delete.

Insert an element (with table Patient as example but could be other tables):

db->Insert<Patient>(patient);
db->Insert<Patient>(vector_of_patients); // vector of elements
TableElement * e = db->InsertFromArg("Patient", string_vector); //FIXME

Query:

// First, define a query
typedef odb::query<Patient> QueryType;
QueryType q = (QueryType::name == "toto" and QueryType::age < 20)

db->Query<Patient>(vector_of_patients); // Get all patients
db->Query<Patient>(q, vector_of_patients); // Get all patients matching the query
patient = db->QueryOne(q);  // Get only one patient matching the query
patient = db->QueryOne(id); // Get only one patient with id

int n = db->Count(q);
if (db->IfExist<Patient>(id)) { ... }

Update:

db->Update<Patient>(patient);
db->Update<Patient>(vector_of_patients);

Delete:

db->Delete<Patient>(patient);
db->Delete<Patient>(vector_of_patients);

Exceptions. Every access to a database can fail for one reason, you can test the result with a try/catch. See here:

try {
// Here, access to the database (insert, query etc)
}
catch (const Exception & e) {
std::cout << e->what(); // Go here if something wrong
}

For debug, you can access to the last SQL query with:

std::string s = db->GetLastSQLQuery();

StandardDatabase

List of tables: TODO

Main class

Direct access to retrieve a patient, an injection:

patient = db->FindPatientByNameOrStudyId("toto");
injection = db->FindInjectionByNameOrId(patient, "Indium111");

DicomSerieBuilder

Create an object DicomSerieBuilder and set the basics informations:

DicomSerieBuilder b(db);
b.SetInjection(injection);
b.SetForcePatientFlag(true);
b.SearchForFilesInFolder(folder, files);

Main function to create a DicomSerie from a file. Checks if the file is not already in the db, guess if the file should be added to an existing DicomSerie or if a new DicomSerie. The DicomSerie is not yet inserted into the db. See next function.

for(auto f:files) b.CreateDicomSerieFromFile(f.c_str());

Once the files have been created (previous function), insert all created series in the db.

b.InsertDicomSeries();

TimepointBuilder

Create an object TimepointBuilder and set the basics informations:

TimepointBuilder b(db);
b.SetTag(tag);
b.SetIntraTimepointMaxHourDiff(1); // 1 hour max difference between

Consider some DicomSerie and create the corresponding Timepoints. Guess that two dicoms with more than 1 hour acquisition time difference are not in the same Timepoint.

for(auto d:dicom_series) b.InsertDicomSerie(d);

Other functions:

GuessState s = b.GuessTimepointForThisDicomSerie(dicom_serie, vector_of_timepoints);
GuessState s = b.GuessIfDicomCanBeInThisTimepoint(dicom_serie, timepoint);
timepoint = b.CreateTimepoint(dicom_serie);
b.AddDicom(timepoint, dicom_serie);

ImageBuilder

Create object Image and the associated mhd/raw image (with itk):

ImageBuilder b(db);
b.SetImageTag(tag);
syd::Image image = b.InsertImageFromDicomSerie(dicom_serie);

Clone this wiki locally