← Back to team overview

phcteam team mailing list archive

[Merge] lp:~leo.robol/clinica-project/data-provider into lp:clinica-project/trunk

 

Leonardo Robol has proposed merging lp:~leo.robol/clinica-project/data-provider into lp:clinica-project/trunk.

Requested reviews:
  PHC Team (phcteam)

For more details, see:
https://code.launchpad.net/~leo.robol/clinica-project/data-provider/+merge/94458

Added abstraction of data provider.
-- 
https://code.launchpad.net/~leo.robol/clinica-project/data-provider/+merge/94458
Your team PHC Team is requested to review the proposed merge of lp:~leo.robol/clinica-project/data-provider into lp:clinica-project/trunk.
=== modified file 'glade/clinica.xml'
--- glade/clinica.xml	2012-02-02 16:52:54 +0000
+++ glade/clinica.xml	2012-02-23 21:39:18 +0000
@@ -3,9 +3,7 @@
 
     <glade-widget-classes>
       <glade-widget-class name="ClinicaCalendarView" generic-name="clinica_calendar_view" title="Calendar View" />
-      <glade-widget-class name="ClinicaDateTimePicker" generic-name="clinica_date_time_picker" title="DateTime picker">
-        <post-create-function>clinica_date_time_picker_glade_init</post-create-function>
-      </glade-widget-class>
+      <glade-widget-class name="ClinicaDateTimePicker" generic-name="clinica_date_time_picker" title="DateTime picker" />
       <glade-widget-class name="ClinicaPatientEntry" generic-name="clinica_patient_entry" title="Patient Entry" />
     </glade-widget-classes>
 

=== modified file 'libclinica/Application.vala'
--- libclinica/Application.vala	2012-01-26 17:41:05 +0000
+++ libclinica/Application.vala	2012-02-23 21:39:18 +0000
@@ -150,7 +150,7 @@
 	            	Intl.bindtextdomain("clinica", null);
 	            
                 /* Init resources */
-                resource_manager.initResources();
+//                resource_manager.initResources();
             }
             
             if (daemon_mode) {

=== modified file 'libclinica/Builder.vala'
--- libclinica/Builder.vala	2012-02-02 07:26:45 +0000
+++ libclinica/Builder.vala	2012-02-23 21:39:18 +0000
@@ -15,7 +15,6 @@
  *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
  *
  *   Authors: Leonardo Robol <leo@xxxxxxxx>
- *            Gianmarco Brocchi <brocchi@xxxxxxxxxxxxxxxxxxxx>
  */
  
  using Gtk;

=== modified file 'libclinica/Calendar.vala'
--- libclinica/Calendar.vala	2011-11-24 08:14:32 +0000
+++ libclinica/Calendar.vala	2012-02-23 21:39:18 +0000
@@ -85,10 +85,10 @@
 				return false;
 			});
 			
-			resource_manager.event_list_store.event_added.connect (on_event_added);
-			resource_manager.event_list_store.event_removed.connect (on_event_removed);
-			resource_manager.visit_list_store.visit_added.connect (on_visit_added);
-			resource_manager.visit_list_store.visit_removed.connect (on_visit_removed);
+			resource_manager.data_provider.event_added.connect (on_event_added);
+			resource_manager.data_provider.event_removed.connect (on_event_removed);
+			resource_manager.data_provider.visit_added.connect (on_visit_added);
+			resource_manager.data_provider.visit_removed.connect (on_visit_removed);
 			realize.connect (() => set_date (today));
 		}
 		
@@ -113,11 +113,11 @@
 			foreach (var day in days) {
 				/* Fill events of the day */
 			    day.reset_events ();
-			    foreach (var visit in Visit.for_day (resource_manager, date, false)) {
+			    foreach (var visit in resource_manager.data_provider.visits (null, date, date.add_days (1))) {
 			        /* Display visits in the day */
 			        day.add_visit (visit);
 			    }
-			    foreach (var event in Event.for_day (resource_manager, date, false)) {
+			    foreach (var event in resource_manager.data_provider.events (date, date.add_days (1))) {
 			        day.add_event (event);
 			    }
 			
@@ -158,15 +158,15 @@
 		 * It should find the day of the event, if present in the view, and 
 		 * insert the events in it.
 		 */
-		private void on_event_added (int event_id) {
-		    update_month ();
-		}
-		
-		private void on_visit_added (int visit_id) {
-		    update_month ();
-		}
-		
-		private void on_visit_removed (int visit_id) {
+		private void on_event_added (int64 event_id) {
+		    update_month ();
+		}
+		
+		private void on_visit_added (int64 visit_id) {
+		    update_month ();
+		}
+		
+		private void on_visit_removed (int64 visit_id) {
 		    update_month ();
 		}
 		
@@ -176,7 +176,7 @@
 		 * It should find the day that contained the event and remove it from the
 		 * view. 
 		 */
-		private void on_event_removed (int event_id) {
+		private void on_event_removed (int64 event_id) {
 		    update_month ();
 		}
 		

=== modified file 'libclinica/CalendarEventList.vala'
--- libclinica/CalendarEventList.vala	2012-02-02 07:26:45 +0000
+++ libclinica/CalendarEventList.vala	2012-02-23 21:39:18 +0000
@@ -45,10 +45,10 @@
             set_size_request (280, -1);
             
             /* Connect event added and or removed with the reload of the day */
-            resource_manager.event_list_store.event_added.connect ((event) => set_day (this.day));
-            resource_manager.event_list_store.event_removed.connect ((event) => set_day (this.day));
-            resource_manager.visit_list_store.visit_added.connect ((visit) => set_day (this.day));
-            resource_manager.visit_list_store.visit_removed.connect ((visit) => set_day (this.day));
+            resource_manager.data_provider.event_added.connect ((event) => set_day (this.day));
+            resource_manager.data_provider.event_removed.connect ((event) => set_day (this.day));
+            resource_manager.data_provider.visit_added.connect ((visit) => set_day (this.day));
+            resource_manager.data_provider.visit_removed.connect ((visit) => set_day (this.day));
         }
         
         public void set_day (DateTime date) {
@@ -75,7 +75,7 @@
             
             /* Show all the events of the day */
             bool no_events = true;
-            foreach (Event event in Event.for_day (resource_manager, date)) {
+            foreach (Event event in resource_manager.data_provider.events (date, date.add_days (1))) {
                 no_events = false;
                 var event_box = new EventDetail (resource_manager, event);
                 box.pack_start (event_box, false, true);
@@ -109,7 +109,7 @@
             
             /* And now the visits of the day */
             bool no_visits = true;
-            foreach (Visit visit in Visit.for_day (resource_manager, date)) {
+            foreach (Visit visit in resource_manager.data_provider.visits (null, date, date.add_days(1))) {
                 no_visits = false;
                 var visit_detail = new VisitDetail (resource_manager, visit);
                 box.pack_start (visit_detail, false, true);

=== modified file 'libclinica/CalendarToolbar.vala'
--- libclinica/CalendarToolbar.vala	2011-11-25 15:02:16 +0000
+++ libclinica/CalendarToolbar.vala	2012-02-23 21:39:18 +0000
@@ -94,8 +94,7 @@
             
             event_editor.set_transient_for (resource_manager.user_interface.calendar_window);
             if (event_editor.run () == EventEditor.Response.SAVE) {
-                event_editor.selected_event.save ();
-                resource_manager.event_list_store.add_event (event_editor.selected_event);
+                resource_manager.data_provider.save_event (event_editor.selected_event);
             }
             event_editor.destroy ();
         }

=== modified file 'libclinica/CalendarWindow.vala'
--- libclinica/CalendarWindow.vala	2011-11-27 23:17:27 +0000
+++ libclinica/CalendarWindow.vala	2012-02-23 21:39:18 +0000
@@ -27,7 +27,7 @@
         internal ResourceManager resource_manager { get; set; }
         internal CalendarView    calendar_view    { get; set; }
         internal CalendarEventList event_widget     { get; set; }
-	internal  CalendarToolbar toolbar { get; private set; }
+        internal  CalendarToolbar toolbar { get; private set; }
     
         public CalendarWindow (ResourceManager resources) {
             GLib.Object (type: WindowType.TOPLEVEL);

=== added file 'libclinica/CoreActivatable.vala'
--- libclinica/CoreActivatable.vala	1970-01-01 00:00:00 +0000
+++ libclinica/CoreActivatable.vala	2012-02-23 21:39:18 +0000
@@ -0,0 +1,46 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+ 
+ namespace Clinica {
+ 
+     public interface CoreActivatable : Object {
+        
+        /** 
+         * @brief The ResourceManager used to interact with clinica.
+         */
+        public abstract ResourceManager resource_manager { get; set; }
+
+        /**
+         * @brief Activate method that will be called when the extension
+         * is loaded. Special hooking up to callbacks and similar can be
+         * done here (registering as data_provider, for example).
+         */        
+        public abstract void activate ();
+        
+        /**
+         * @brief Deactivation method. Here the extension should unplug itself
+         * from the Clinica application.
+         */
+        public abstract void deactivate ();
+        
+        public abstract void update_state ();
+        
+     }
+     
+}

=== added file 'libclinica/CoreActivatableExtensionSet.c'
--- libclinica/CoreActivatableExtensionSet.c	1970-01-01 00:00:00 +0000
+++ libclinica/CoreActivatableExtensionSet.c	2012-02-23 21:39:18 +0000
@@ -0,0 +1,43 @@
+#include <libpeas/peas.h>
+#include <clinica.h>
+#include <stdio.h>
+
+static void
+on_extension_added (PeasExtensionSet *set,
+		    PeasPluginInfo *info,
+		    ClinicaCoreActivatable *activatable)
+{
+    clinica_core_activatable_activate (activatable);
+}
+
+static void
+on_extension_removed (PeasExtensionSet *set,
+		      PeasPluginInfo *info,
+		      ClinicaCoreActivatable *activatable)
+{
+    clinica_core_activatable_deactivate (activatable);
+}
+
+PeasExtensionSet*
+clinica_resource_manager_setup_extension_set (ClinicaResourceManager *rm,
+                                              PeasEngine *engine)
+{
+    PeasExtensionSet *set;
+    
+    set = peas_extension_set_new (engine, CLINICA_TYPE_CORE_ACTIVATABLE,
+				  "resource_manager", rm, NULL);
+
+    g_signal_connect (set, "extension-added",
+		      G_CALLBACK (on_extension_added), NULL);
+    g_signal_connect (set, "extension-removed",
+		      G_CALLBACK (on_extension_removed), NULL);
+#ifdef HAVE_PEAS_EXTENSION_SET_FOREACH
+     peas_extension_set_foreach (set,
+				(PeasExtensionSetForeachFunc) on_extension_added,
+				NULL);
+#else
+     peas_extension_set_call (set, "activate");
+#endif
+
+    return set;
+}

=== added file 'libclinica/DataProvider.vala'
--- libclinica/DataProvider.vala	1970-01-01 00:00:00 +0000
+++ libclinica/DataProvider.vala	2012-02-23 21:39:18 +0000
@@ -0,0 +1,241 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+ 
+ namespace Clinica {
+ 
+    public interface VisitIterator : Object {
+        public abstract Visit get ();
+        public abstract bool next ();
+        public VisitIterator iterator () { return this; }
+    }
+    
+    public interface PatientIterator : Object {
+        public abstract Patient get ();
+        public abstract bool next  ();
+        public PatientIterator iterator () { return this; }
+    }
+    
+    public interface DoctorIterator : Object {
+        public abstract Doctor get ();
+        public abstract bool next  ();
+        public DoctorIterator iterator () { return this; }        
+    }
+    
+    public interface EventIterator : Object {
+        public abstract Event get ();
+        public abstract bool next ();
+        public EventIterator iterator () { return this; }        
+    }
+ 
+    public interface DataProvider : Object {
+    
+        /**
+         * @brief Get the name of the DataProvider object. This must be a unique
+         * name since it will be used to identify it and to select the right
+         * DataProvider on startup.
+         */
+        public abstract string get_name ();
+    
+        /**
+         * @brief Get the visit with the given id.
+         */
+        public abstract Visit get_visit (int64 id);
+        
+        /**
+         * @brief Save a Visit. If the ID associated is 0
+         * than a new ID will be created and will be returned.
+         */
+        public abstract int64 save_visit (Visit visit);
+        
+        /**
+         * @brief Remove a Visit from the database. This routine
+         * will return 0 on success.
+         */
+        public abstract int64 remove_visit (Visit visit);
+        
+        /**
+         * @brief Emitted when a visit changes in the Database; this means
+         * that all Visit object with this ID around must be invalidated and
+         * reloaded.
+         */
+        public signal void visit_changed (int64 id);
+        
+        /**
+         * @brief Emitted when a visit is removed from the database. This means
+         * that all the Visit with this id must be removed. Please note that you
+         * can't call get_visit () with this ID since the visit has already been
+         * removed.
+         */
+        public signal void visit_removed (int64 id);
+        
+        /**
+         * @brief Emitted when a new visit is added to the database.
+         */
+        public signal void visit_added   (int64 id);
+        
+        /**
+         * @brief Iterate on all the visits
+         *
+         * @param patient If not null then pick up only the visits of the given patient.
+         * @param start If not null pick up only visits from this starting date.
+         * @param end If not null stop iterating on visits when this date is reached.
+         */
+        public abstract VisitIterator visits (Patient? patient = null, DateTime? start = null, DateTime? end = null);
+        
+        /**
+         * @brief Get the Patient with the given id.
+         */
+        public abstract Patient get_patient (int64 id);
+        
+        /**
+         * @brief Save a Patient. If the ID associated is 0
+         * than a new ID will be created and will be returned.
+         */
+        public abstract int64 save_patient (Patient patient);
+        
+        /**
+         * @brief Remove a Patient from the database. This routine
+         * will return 0 on success.
+         *
+         * This routine must take care of removing all the patients
+         * visits and deassociate all the events from this patient.
+         */        
+        public abstract int64 remove_patient (Patient patient);
+        
+        /**
+         * @brief Emitted when a patient changes in the database; this means
+         * that all Patient objects with this ID around must be invalidated and
+         * reloaded.
+         */
+        public signal void patient_changed (int64 id);
+        
+        /**
+         * @brief Emitted when a patient is removed from the database. This means
+         * that all the Patients with this id must be removed. Please note that you
+         * can't call get_patient () with this ID since the patient has already been
+         * removed.
+         */        
+        public signal void patient_removed (int64 id);
+        
+        /**
+         * @brief Emitted when a new patient is added to the database.
+         */        
+        public signal void patient_added   (int64 id);
+        
+        /**
+         * @brief Iterate over all the patients in the database.
+         *
+         * @param doctor If doctor is not null iterate only on patients associated
+         * on this doctor.
+         */
+        public abstract PatientIterator patients (Doctor? doctor = null);
+        
+        /**
+         * @brief Get the doctor associatied with the given id.
+         */
+        public abstract Doctor get_doctor (int64 id);
+        
+        /**
+         * @brief Save a Doctor. If the ID associated is 0
+         * than a new ID will be created and will be returned.
+         */
+        public abstract int64 save_doctor (Doctor doctor);
+
+        /**
+         * @brief Remove a Doctor from the database. This routine
+         * will return 0 on success.
+         *
+         * This routine must take care of deassociating of the
+         * patients of this doctor from him/her.
+         */        
+        public abstract int64 remove_doctor (Doctor doctor);
+        
+        /**
+         * @brief Emitted when a doctor changes in the database; this means
+         * that all Doctor objects with this ID around must be invalidated and
+         * reloaded.
+         */
+        public signal void doctor_changed (int64 id);
+        
+        /**
+         * @brief Emitted when a doctor is removed from the database. This means
+         * that all the Doctor with this id must be removed. Please note that you
+         * can't call get_doctor () with this ID since the doctor has already been
+         * removed.
+         */           
+        public signal void doctor_removed (int64 id);
+        
+        /**
+         * @brief Emitted when a new doctor is added to the database.
+         */           
+        public signal void doctor_added   (int64 id);
+        
+        /**
+         * @brief Iteratate over all the doctors in the database.
+         */
+        public abstract DoctorIterator doctors ();
+        
+        /**
+         * @brief Get the event associated to the given ID.
+         */
+        public abstract Event get_event (int64 id);
+        
+        /**
+         * @brief Save an Event. If the ID associated is 0
+         * than a new ID will be created and will be returned.
+         */
+        public abstract int64 save_event (Event event);
+        
+        /**
+         * @brief Remove the event from the database.
+         */
+        public abstract int64 remove_event (Event event);
+        
+        /**
+         * @brief Emitted when an event changes in the database; this means
+         * that all Event objects with this ID around must be invalidated and
+         * reloaded.
+         */
+        public signal void event_changed (int64 id);
+        
+        /**
+         * @brief Emitted when an event is removed from the database. This means
+         * that all the Event with this id must be removed. Please note that you
+         * can't call get_event () with this ID since the event has already been
+         * removed.
+         */   
+        public signal void event_removed (int64 id);
+        
+        /**
+         * @brief Emitted when a new event is added to the database.
+         */
+        public signal void event_added   (int64 id);
+        
+        /**
+         * @brief Iterate over all the events in the database.
+         *
+         * @param from If from is not null then iterate only from events starting after
+         * from.
+         * @param to If to is not null then iterate only until events before to.
+         */
+        public abstract EventIterator events (DateTime? from = null, DateTime? to = null);
+    
+    }
+ 
+ }

=== modified file 'libclinica/DateTimePicker.vala'
--- libclinica/DateTimePicker.vala	2012-02-02 17:48:45 +0000
+++ libclinica/DateTimePicker.vala	2012-02-23 21:39:18 +0000
@@ -20,27 +20,20 @@
  
  namespace Clinica {
     
-    public class DateTimePicker : Gtk.EventBox, Buildable {
+    public class DateTimePicker : Gtk.EventBox, Buildable, Gtk.Buildable {
     
         private Gtk.Calendar calendar;
         
         private Gtk.SpinButton hour_spinbutton;
         private Gtk.SpinButton minute_spinbutton;
         
-        public static void glade_init (Object adaptor, DateTimePicker picker, int reason) {
-            picker.create_interface ();
-        }
-        
         public void setup (ResourceManager resources) {
-            create_interface ();
-            show_all ();
         }
     
         public DateTimePicker () {
-            create_interface ();
         }
-            
-        public void create_interface () {
+        
+        construct {
             var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
             
             calendar = new Gtk.Calendar ();
@@ -69,6 +62,8 @@
             add (vbox);
             
             calendar.set_margin_bottom (6);
+            
+            show_all ();
         }
         
         private void on_hour_spinbutton_changed (Gtk.Editable spin) {

=== modified file 'libclinica/Day.vala'
--- libclinica/Day.vala	2011-12-19 06:28:10 +0000
+++ libclinica/Day.vala	2012-02-23 21:39:18 +0000
@@ -94,8 +94,7 @@
 		    event_editor.set_transient_for (resource_manager.user_interface.calendar_window);
             if (event_editor.run () == EventEditor.Response.SAVE) {
                 /* Save the event in the editor */
-                event_editor.selected_event.save ();
-                resource_manager.event_list_store.add_event (event_editor.selected_event);
+                resource_manager.data_provider.save_event (event_editor.selected_event);
             }
 		    event_editor.destroy ();
 		    return true;
@@ -180,7 +179,7 @@
                 ctx.set_font_size (10.0);
                 double line_position = 20;
                 double line_height = 13.0;
-                Gee.LinkedList<int> displayed_patients_id = new Gee.LinkedList<int> ();
+                Gee.LinkedList<int64?> displayed_patients_id = new Gee.LinkedList<int64?> ();
     	        ctx.rectangle (0, 0, width - 4, height - 4);
 		        ctx.clip ();
 			    
@@ -208,9 +207,9 @@
 			    
 			    /* Drawing performed visits */
 			    foreach (var visit in visit_list) {
-			        if (visit.patient.get_id () in displayed_patients_id)
+			        if (visit.patient.id in displayed_patients_id)
 			            continue;
-			        displayed_patients_id.add (visit.patient.get_id ());
+			        displayed_patients_id.add (visit.patient.id);
 			        string text = "Visit: " + visit.patient.get_complete_name ();;
 			        ctx.text_extents (text, out extents);
 			        ctx.move_to (4 - extents.x_bearing,
@@ -291,7 +290,7 @@
 		 */
 		public void remove_visit (Visit visit) {
 		    foreach (var v in visit_list) {
-		        if (v.get_id () == visit.get_id ()) {
+		        if (v.id == visit.id) {
 		            visit_list.remove (v);
         		    area.queue_draw ();
 		            return;
@@ -312,7 +311,7 @@
 		 */
 		public void remove_event (Event event) {
 		    foreach (var e in event_list) {
-		        if (e.get_id () == event.get_id ()) {
+		        if (e.id == event.id) {
 		            event_list.remove (e);
 		            area.queue_draw ();
 		            return;

=== modified file 'libclinica/Doctor.vala'
--- libclinica/Doctor.vala	2011-09-22 19:27:52 +0000
+++ libclinica/Doctor.vala	2012-02-23 21:39:18 +0000
@@ -15,104 +15,36 @@
  *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
  *
  *   Authors: Leonardo Robol <leo@xxxxxxxx>
- *            Gianmarco Brocchi <brocchi@xxxxxxxxxxxxxxxxxxxx>
  */
- 
- using Gee;
- using Sqlite;
- 
- namespace Clinica {
- 
-         
-    public class DoctorIterator : SqlDataIterator {
-    
-		private ResourceManager resource_manager;
-    
-    	/**
-    	 * @brief Iterator over all the Doctors present
-    	 * in the database. 
-    	 */
-        public DoctorIterator (ResourceManager resources) {
-            base (resources.db, resources.doctor_table);
-            resource_manager = resources;
-        }
-        
-        public new DoctorIterator iterator () { return this; }
-        
-        public new Doctor get () {
-            return new Doctor.with_id (resource_manager, base.get ());
-        }
+
+namespace Clinica {
+
+    public class Doctor : Object {
+    
+        public DataProvider? provider = null;
+    
+        public int64 id { get; set; default = 0; }
+        
+        public string given_name { get; set; }
+        
+        public string surname { get; set; }
+        
+        public string phone { get; set; }
+        
+        public string mobile { get; set; }
+        
+        public string get_complete_name () {
+        	return string.join (" ", this.given_name, this.surname);
+        }
+        
+        public PatientIterator patients () {
+            return provider.patients (this);
+        }
+        
+        public bool has_patients () {
+            return (patients ().next ());
+        }
+        
     }
- 
-    /**
-     * @brief A doctor associated with some patients
-     */
-    public class Doctor : SqlDataType {
-        
-        public new static DoctorIterator all (ResourceManager resources) {
-            return new DoctorIterator (resources);
-        }
-        
-        /* FIELDS */
-        public string given_name {
-        	get { return get_text ("given_name"); }
-        	set { set_text ("given_name", value); }
-        }
-        
-        public string surname {
-        	get { return get_text ("surname"); }
-        	set { set_text ("surname", value); }
-        }
-        
-        public string phone {
-        	get { return get_text ("phone"); }
-        	set { set_text ("phone", value); }
-        }
-        
-        public string mobile {
-        	get { return get_text ("mobile"); }
-        	set { set_text ("mobile", value); }
-        }
-        
-		private ResourceManager resource_manager;
-    
-        public Doctor (ResourceManager resources) {
-            base (resources.db);
-            resource_manager = resources;
-            table_name = resources.doctor_table;
-            error.connect ((t,l) => resources.error_callback(t,l));
-            
-            add_text_field ("given_name");
-            add_text_field ("surname");
-            add_text_field ("phone");
-            add_text_field ("mobile");
-            
-            /* Finishing connecting the object to the database */
-            init_resources ();
-        }
-        
-        public Doctor.with_id (ResourceManager resources, int ID) {
-            this (resources);
-            load (ID);
-        }
-        
-        public string get_complete_name () {
-        	return string.join(" ", given_name, surname);
-       	}
-       	
-       	public bool has_patients () {
-       		GLib.List<int> associated_ids = associated_ids(resource_manager.patient_table, "doctor");
-       		return (associated_ids.length () != 0);
-       	}
-       	
-       	public new void remove () {
-       		if (has_patients ()) 
-       			error (_("You cannot delete a doctor with associated patients. Delete his patients first."));
-       		else
-	       		base.remove ();
-       	}
-        
-        
 
-    }   
- }
+}

=== modified file 'libclinica/DoctorEditor.vala'
--- libclinica/DoctorEditor.vala	2012-01-31 09:43:09 +0000
+++ libclinica/DoctorEditor.vala	2012-02-23 21:39:18 +0000
@@ -50,7 +50,7 @@
 		    resource_manager = resources;
 			error.connect ((me, message) => resource_manager.error_callback (me, message));
 		
-			builder = new Clinica.Builder.with_filename (resources, "doctor-editor.glade");
+			builder = new Clinica.Builder.with_filename (resources, "doctor_editor.glade");
 			builder.load_into_dialog (this);
 			
 			/* Pack buttons and content */
@@ -85,7 +85,7 @@
 			mobile_entry.set_text (doctor.mobile);
 			
 			/* Set title of edit doctor dialog, space is important! */
-			set_title (_("Edit doctor named %s").printf(doctor.get_complete_name ()));
+			set_title (_("Edit doctor named %s").printf (doctor.get_complete_name ()));
 		}
 		
 		/**
@@ -111,7 +111,7 @@
 			if (base.run () == Response.SAVE) {
 				Doctor doc;
 				if (existing_doctor == null)		
-					doc = new Doctor (resource_manager);
+					doc = new Doctor ();
 				else
 					doc = existing_doctor;
 				
@@ -120,14 +120,9 @@
 				doc.surname    = surname_entry.get_text ();
 				doc.phone      = phone_entry.get_text ();
 				doc.mobile     = mobile_entry.get_text ();
-				doc.save ();
-		
-				if (existing_doctor == null) {
-					created_doctor = doc;
-					resource_manager.doctor_list_store.add_doctor (doc);
-				} else {
-					resource_manager.doctor_list_store.reload_doctor (doc);
-				}
+				int64 new_id = resource_manager.data_provider.save_doctor (doc);
+				
+				created_doctor = resource_manager.data_provider.get_doctor (new_id);
 				
 				return Response.SAVE;
 			}

=== modified file 'libclinica/DoctorListStore.vala'
--- libclinica/DoctorListStore.vala	2011-09-28 06:45:15 +0000
+++ libclinica/DoctorListStore.vala	2012-02-23 21:39:18 +0000
@@ -47,43 +47,61 @@
             
             /* Asynchronous loading of doctors... */
             Idle.add (() => {
-	            foreach (Doctor doc in Doctor.all (resource_manager)) {
-    	        	add_doctor (doc);
+	            foreach (Doctor doc in resource_manager.data_provider.doctors ()) {
+    	        	add_doctor (doc.id);
     	        }
     	        
+    	        /* Setup callbacks to add or remove doctors */
+		        resource_manager.data_provider.doctor_added.connect (
+		            (id) => add_doctor (id));
+		        resource_manager.data_provider.doctor_changed.connect (
+		            (id) => reload_doctor (id));
+		        resource_manager.data_provider.doctor_removed.connect (
+		            (id) => remove_doctor (id));
+    	        
     	        /* We don't need to execute any more */
     	        return false;
     	    });
         }
         
-        public void add_doctor (Doctor doc) {
-        	TreeIter it;
-            append(out it);
-            set_value (it, Field.DOCTOR, doc);
-            set_value (it, Field.GIVEN_NAME, doc.given_name);
-            set_value (it, Field.SURNAME, doc.surname);
-            set_value (it, Field.COMPLETE_NAME, doc.get_complete_name ());
-        }
-        
-        public void reload_doctor (Doctor doc) {
-        	TreeIter it;
-        	Value doctor;
-        	int this_id = doc.get_id ();
+        private TreeIter id_to_iter (int64 id) {
+            TreeIter it;
+            Value doctor;
         	if (!get_iter_first (out it)) {
         		error (_("Doctors database seems corrupted."));
         	}
         	do {
         		get_value (it, Field.DOCTOR, out doctor);
-        		if ((doctor as Doctor).get_id () == this_id) {			
-		            set_value (it, Field.DOCTOR, doc);
-		            set_value (it, Field.GIVEN_NAME, doc.given_name);
-		            set_value (it, Field.SURNAME, doc.surname);
-		            set_value (it, Field.COMPLETE_NAME, doc.get_complete_name ());
-		            return;
+        		if ((doctor as Doctor).id == id) {
+		            return it;
         		}
         	} while (iter_next (ref it));
         	
-        	assert_not_reached ();
+        	return it;
+        }
+        
+        private void add_doctor (int64 id) {
+            Doctor doc = resource_manager.data_provider.get_doctor (id);
+        	TreeIter it;
+            append(out it);
+            set_value (it, Field.DOCTOR, doc);
+            set_value (it, Field.GIVEN_NAME, doc.given_name);
+            set_value (it, Field.SURNAME, doc.surname);
+            set_value (it, Field.COMPLETE_NAME, doc.get_complete_name ());
+        }
+        
+        private void reload_doctor (int64 id) {
+            Doctor doc = resource_manager.data_provider.get_doctor (id);
+            TreeIter it = id_to_iter (id);		
+            set_value (it, Field.DOCTOR, doc);
+		    set_value (it, Field.GIVEN_NAME, doc.given_name);
+		    set_value (it, Field.SURNAME, doc.surname);
+		    set_value (it, Field.COMPLETE_NAME, doc.get_complete_name ());
+        }
+        
+        private void remove_doctor (int64 id) {
+            TreeIter iter = id_to_iter (id);
+            remove (iter);
         }
     }
 }

=== modified file 'libclinica/DoctorListView.vala'
--- libclinica/DoctorListView.vala	2012-01-31 08:10:13 +0000
+++ libclinica/DoctorListView.vala	2012-02-23 21:39:18 +0000
@@ -126,7 +126,7 @@
          * @brief Return an iter in the DoctorListStore associated
          * with the current selection, or null
          */
-        private TreeIter? get_selected_iter () {
+        public TreeIter? get_selected_iter () {
         	TreeSelection selection = get_selection ();
         	TreeIter iter;
         	TreeModel model;
@@ -184,7 +184,7 @@
 		    			MessageType.QUESTION, ButtonsType.YES_NO, "%s", "");
 		    			warning_dialog.set_markup(
 		    				_("The doctor that you have selected for removal has some patients associated. \n") +
-		    				_("It's not possible to remove it without removing all his patients.\n\n") +
+		    				_("It's not possible to remove it without disassociating all his patients.\n\n") +
 		    				_("Do you really want to proceed?"));
 		    			warning_dialog.set_title (_("Doctor has associated patients"));
 		    			warning_dialog.set_transient_for (resource_manager.user_interface.window);
@@ -197,18 +197,14 @@
 		    			warning_dialog.destroy ();
 		    			
 		    			/* Get List of the patients to remove and delete them */
-		    			List<TreeIter?> iters = resource_manager.patient_list_store.get_patients_of (doc);
-		    			
-		    			/* This will be used to retrieve data from liststores */
-		    			Value value;
+		    			PatientIterator patients = doc.patients ();
 		    			
 		    			/* Create an array with the names oft he patients 
 		    			 * that will be deleted */
 		    			string [] patient_names = {};
 		    			
-		    			foreach(TreeIter? it in iters) {
-		    				resource_manager.patient_list_store.get_value (it, 0, out value);
-		    				patient_names += " - <b>" + (value as Patient).get_complete_name() + "</b>";
+		    			foreach(Patient p in patients) {
+		    				patient_names += " - <b>" + p.get_complete_name() + "</b>";
 		    			}
 		    			
 		    			/* Warn another time the user that these patients will be deleted and
@@ -216,10 +212,10 @@
 		    			warning_dialog = new MessageDialog(null, DialogFlags.MODAL | DialogFlags.DESTROY_WITH_PARENT,
 		    				MessageType.QUESTION, ButtonsType.YES_NO, "%s", "");
 		    			warning_dialog.set_markup (
-		    				_("The following patients will be deleted by this action:\n") + 
+		    				_("The following patients will be disassociated from this doctor by this action:\n") + 
 		    				string.joinv("\n", patient_names) + "\n" +
 		    				_("Do you really want to proceed?"));
-		    			warning_dialog.set_title (_("Confirm deletion of patients"));
+		    			warning_dialog.set_title (_("Confirm disassociation of patients"));
 		    			warning_dialog.set_transient_for (resource_manager.user_interface.window);
 		    			
 		    			if (warning_dialog.run () != ResponseType.YES) {
@@ -229,11 +225,6 @@
 		    			
 		    			/* If we got here then the user is really sure, so delete the patients */
 		    			warning_dialog.destroy ();
-		    			foreach (TreeIter? it in iters) {
-		    				resource_manager.patient_list_store.get_value (it, 0, out value);
-		    				(value as Patient).remove ();
-		    				resource_manager.patient_list_store.remove (it);
-		    			}
 		    		}
 		    	}
 		    	else {
@@ -251,8 +242,7 @@
 		    	}
 		    	
 		    	/* Proceed with the removal of the doctor */
-		    	doc.remove ();
-		    	resource_manager.doctor_list_store.remove(get_selected_iter ());
+		    	resource_manager.data_provider.remove_doctor (doc);
 		    }
         
         }

=== added file 'libclinica/EmptyVisitIterator.vala'
--- libclinica/EmptyVisitIterator.vala	1970-01-01 00:00:00 +0000
+++ libclinica/EmptyVisitIterator.vala	2012-02-23 21:39:18 +0000
@@ -0,0 +1,30 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+ 
+ namespace Clinica {
+ 
+    public class EmptyVisitIterator : GLib.Object, VisitIterator {
+    
+        public VisitIterator iterator () { return this; }
+        public bool next () { return false; }
+        public new Visit get () { return new Visit (); }
+    
+    }
+ 
+ }

=== modified file 'libclinica/Event.vala'
--- libclinica/Event.vala	2011-10-10 06:54:39 +0000
+++ libclinica/Event.vala	2012-02-23 21:39:18 +0000
@@ -15,158 +15,39 @@
  *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
  *
  *   Authors: Leonardo Robol <leo@xxxxxxxx>
- *            Gianmarco Brocchi <brocchi@xxxxxxxxxxxxxxxxxxxx>
  */
- 
+
 namespace Clinica {
 
-    public class EventIterator : SqlDataIterator {
-    
-        private ResourceManager resource_manager { get; set; }
-        
-        public EventIterator (ResourceManager resources) {
-            /* Grab the resource manager and chain the SqlDataIterator constructor,
-             * ordering by date in decreasing order. */
-            base (resources.db, resources.events_table, "date", false);
-            resource_manager = resources;
-        }
-        
-        public EventIterator.with_day (ResourceManager resources, DateTime date, bool descending = true) {
-            base.with_like (resources.db, resources.events_table, "date", descending, 
-                "date BETWEEN '%s' AND '%s'".printf (SqlDataType.datetime_to_string (date),
-                                                     SqlDataType.datetime_to_string (date.add_days (1).add_minutes(-1))));
-            resource_manager = resources;
-        }
-        
-        public new EventIterator iterator () {
-            return this;
-        }
-        
-        public new Event get () {
-            return new Event.with_id (resource_manager, base.get ());
-        }
-    }
-
-    public class Event : SqlDataType {
-    
-        private ResourceManager resource_manager { get; set; }
-        
-        /* Properties mapped to the database */
-        public string title {
-            get { return get_text ("title"); }
-            set { set_text ("title", value); }
-        }
-        
-        public string description {
-            get { return get_text ("description"); }
-            set { set_text ("description", value); }
-        }
-        
-        public string venue {
-            get { return get_text ("venue"); }
-            set { set_text ("venue", value); }
-        }
+    public class Event : Object {
+    
+        public DataProvider? provider = null;
+        
+        public int64 id { get; set; default = 0; }
+    
+        public string title { get; set; }
+        
+        public string description { get; set; }
+        
+        public string venue { get; set; }
         
         /** 
          * @brief Patient associated to this event, if one exists,
          * or null otherwise
          */
-        private Patient? _patient;
-        public Patient? patient {
-            get { 
-                int id = get_integer ("patient");
-                if (id == 0) {
-                    return null;
-                }
-                else {
-                    _patient = new Patient.with_id (resource_manager, id);
-                    return _patient;
-                }
-            }
-            set {
-                if (value != null) {
-                    set_integer ("patient", value.get_id ());
-                    _patient = value;
-                }
-                else {
-                    set_integer ("patient", 0);
-                }
-            }
-        }
-        
+        public Patient? patient { get; set; }
         
         /** 
          * @brief Visit associated to this event, if one exists,
          * or null otherwise
          */
-        private Visit? _visit;
-        public Visit? visit {
-            get { 
-                int id = get_integer ("visit");
-                if (id == 0) {
-                    return null;
-                }
-                else {
-                    _visit = new Visit.with_id (resource_manager, id);
-                    return _visit;
-                }
-            }
-            set {
-                if (value != null) {
-                    set_integer ("visit", value.get_id ());
-                    _visit = value;
-                }
-                else {
-                    set_integer ("visit", 0);
-                }
-            }
-        }
+        public Visit? visit { get; set; }
         
         /**
          * @brief Date associated to this event.
          */
-        private DateTime _date;
-        public DateTime date {
-        	get { 
-        		_date = get_date ("date");
-        		return _date;
-        	}
-        	set {
-        		_date = value;
-        		set_date ("date", _date);
-        	}
-        }
+        public DateTime date { get; set; }
     
-        public Event (ResourceManager resources) {
-            base (resources.db);
-            resource_manager = resources;
-            error.connect ((t,l) => resources.error_callback(t,l));
-            table_name = resource_manager.events_table;
-            
-            add_text_field ("title");
-            add_text_field ("description");
-            add_text_field ("venue");
-            add_integer_field ("patient");
-            add_integer_field ("visit");
-            add_date_field ("date");
-            
-            init_resources ();
-            
-            visit = null;
-            patient = null;
-        }
-        
-        public Event.with_id (ResourceManager resources, int id) {
-            this (resources);
-            load (id);
-        }
-        
-        public static new EventIterator all (ResourceManager resources) {
-            return new EventIterator (resources);
-        }
-        
-        public static new EventIterator for_day (ResourceManager resources, DateTime date, bool descending = false) {
-            return new EventIterator.with_day (resources, date, descending);
-        }
     }
+
 }

=== modified file 'libclinica/EventDetail.vala'
--- libclinica/EventDetail.vala	2012-02-02 08:38:15 +0000
+++ libclinica/EventDetail.vala	2012-02-23 21:39:18 +0000
@@ -55,6 +55,7 @@
             title_label.set_alignment (0.0f, 0.5f);
             title_label.set_size_request (120, -1);
             title_label.set_line_wrap (true);
+            title_label.set_valign (Align.START);
             box.pack_start (title_label);
             
             /* Adding action buttons, such as edit and delete */
@@ -131,9 +132,7 @@
             var event_editor = new EventEditor (resource_manager, associated_event);
             event_editor.set_transient_for (resource_manager.user_interface.calendar_window);            
             if (event_editor.run () == EventEditor.Response.SAVE) {
-                event_editor.selected_event.save ();
-                resource_manager.event_list_store.remove_event (event_editor.selected_event);
-                resource_manager.event_list_store.add_event (event_editor.selected_event);
+                resource_manager.data_provider.save_event (event_editor.selected_event);
             }
             
             event_editor.destroy ();
@@ -151,8 +150,7 @@
        		}
        		question.destroy ();
         		
-            associated_event.remove ();
-            resource_manager.event_list_store.remove_event (associated_event);
+            resource_manager.data_provider.remove_event (associated_event);
         }
     }
  }

=== modified file 'libclinica/EventEditor.vala'
--- libclinica/EventEditor.vala	2011-11-12 15:14:56 +0000
+++ libclinica/EventEditor.vala	2012-02-23 21:39:18 +0000
@@ -89,7 +89,7 @@
             /* If the event is null, let's create a new one, otherwise
              * store the event passed for editing. */
             if (event == null) {
-                selected_event = new Event (resource_manager);
+                selected_event = new Event ();
                 set_title (_("Create a new event"));
             }
             else {

=== added file 'libclinica/EventIterator.vala'
--- libclinica/EventIterator.vala	1970-01-01 00:00:00 +0000
+++ libclinica/EventIterator.vala	2012-02-23 21:39:18 +0000
@@ -0,0 +1,44 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+ 
+using Sqlite;
+
+namespace Clinica {
+   
+    public class SqliteEventIterator : Object, EventIterator {
+        
+		private SqliteDataProvider provider;
+		private Statement stmt;
+
+        public SqliteEventIterator (SqliteDataProvider provider, string clause = "") {
+            this.provider = provider;
+            provider.db.prepare ("SELECT id from %s %s ORDER by date DESC;".printf (provider.event_table, clause), 
+                                 -1, out stmt);
+        }
+        
+        public bool next () {
+            return (stmt.step () == ROW);
+        }
+        
+        public new Event get () {
+            int id = stmt.column_int (0);
+            return provider.get_event (id); 
+        }
+    }
+}

=== modified file 'libclinica/EventListStore.vala'
--- libclinica/EventListStore.vala	2011-11-26 11:40:13 +0000
+++ libclinica/EventListStore.vala	2012-02-23 21:39:18 +0000
@@ -24,9 +24,6 @@
     
     public class EventListStore : ListStore {
     
-        public signal void event_added   (int event_id);
-        public signal void event_removed (int event_id);
-    
         /**
          * @brief Fields present in the store, i.e. header of
          * the columns.
@@ -63,12 +60,38 @@
                 
             set_column_types (column_headers);
             GLib.Idle.add (load_events_from_db);
+            
+	        /* Setup callbacks to add or remove events */
+	        resource_manager.data_provider.event_added.connect (
+	            (id) => add_event (id));
+	        resource_manager.data_provider.event_changed.connect (
+	            (id) => reload_event (id));
+	        resource_manager.data_provider.event_removed.connect (
+	            (id) => remove_event (id));
+        }
+        
+        /**
+         * @brief Reload information about an event
+         */
+        private void reload_event (int64 id) {
+            var event = resource_manager.data_provider.get_event (id);
+            TreeIter iter = id_to_iter (id);
+            
+            /* Set values in the treeview */
+            set_value (iter, Field.EVENT, event);
+            set_value (iter, Field.DATE, event.date);
+            set_value (iter, Field.DESCRIPTION, event.description);
+            set_value (iter, Field.PATIENT, event.patient);
+            set_value (iter, Field.TITLE, event.title);
+            set_value (iter, Field.VENUE, event.venue);
+            set_value (iter, Field.VISIT, event.visit);
         }
         
         /**
          * @brief Add an event to the liststore.
          */
-        public void add_event (Event event) {
+        public void add_event (int64 id) {
+            var event = resource_manager.data_provider.get_event (id);
             TreeIter iter;
             append (out iter);
             
@@ -80,31 +103,28 @@
             set_value (iter, Field.TITLE, event.title);
             set_value (iter, Field.VENUE, event.venue);
             set_value (iter, Field.VISIT, event.visit);
-            
-            /* Emit event_added to make calendars and other pieces of interface
-             * using events know that they must reload their dates */
-            event_added (event.get_id ());
-        }
-        
-        public void remove_event (Event event) {
+        }
+        
+        public void remove_event (int64 id) {
+            remove (id_to_iter (id));
+        }
+        
+        private TreeIter id_to_iter (int64 id) {
             TreeIter iter;
             Value value;
+            
             if (!get_iter_first (out iter)) {
                 error (_("Events database seems corrupted. This is likely to be a bug in the application"));
             }
             
             do {
                 get_value (iter, Field.EVENT, out value);
-                if ((value as Event).get_id () == event.get_id ()) {
-                    /* Delete this event from the liststore */
-                    int event_id = event.get_id ();
-                    remove (iter);
-                    event_removed (event_id);
-                    return;
+                if ((value as Event).id == id) {
+                    return iter;
                 }
             } while (iter_next (ref iter));
             
-            assert_not_reached ();
+            return iter;
         }
         
         /**
@@ -114,8 +134,8 @@
          * This function is now called by default from the constructor.
          */
         private bool load_events_from_db () {
-            foreach (var event in Event.all (resource_manager)) {
-                add_event (event);
+            foreach (var event in resource_manager.data_provider.events ()) {
+                add_event (event.id);
             }
             
             return false;

=== modified file 'libclinica/FileObject.vala'
--- libclinica/FileObject.vala	2012-01-27 13:36:57 +0000
+++ libclinica/FileObject.vala	2012-02-23 21:39:18 +0000
@@ -38,13 +38,13 @@
         /**
          * @brief The ID of the file store where this file is saved.
          */
-        int id;
+        int64 id;
         
         /**
          * @brief Generate a FileObject starting from an existing file.
          * A copy of that filed will be stored in the FileStore specified.
          */
-        public FileObject (FileStore store, int id, string filename, bool in_store = false) {
+        public FileObject (FileStore store, int64 id, string filename, bool in_store = false) {
             this.store = store;
             this.id = id;
             if (!in_store)
@@ -57,7 +57,7 @@
          * @brief Obtain the ID in the file store where the file can
          * be retrieved.
          */
-        public int get_id () {
+        public int64 get_id () {
             return id;
         }
         

=== modified file 'libclinica/FileStore.vala'
--- libclinica/FileStore.vala	2012-01-29 15:44:14 +0000
+++ libclinica/FileStore.vala	2012-02-23 21:39:18 +0000
@@ -32,7 +32,7 @@
          * @brief Signal emitted when the FileStore changes. This invalidates
          * all the FileObjects around, that must be reloaded.
          */
-        public signal void changed (int id);
+        public signal void changed (int64 id);
         
         /**
          * @brief Signal emitted when something goes wrong :)
@@ -48,13 +48,13 @@
          * @brief List of directories that are monitored by the
          * GioFileMonitor, so we don't monitor the twice.
          */
-        private GLib.List<int> monitored_ids;
+        private GLib.List<int64?> monitored_ids;
         
         public FileStore (ResourceManager resources) {
             resource_manager = resources;
             error.connect ((t,l) => resource_manager.error_callback (t,l));
             
-            monitored_ids = new GLib.List<int> ();
+            monitored_ids = new GLib.List<int64?> ();
             
             /* Setup some monitored folders */
             try {
@@ -63,7 +63,7 @@
                 
                 FileInfo info;
                 while ((info = enumerator.next_file ()) != null) {
-                    int id = int.parse (info.get_name ());
+                    int64 id = int64.parse (info.get_name ());
                     if (id.to_string () == info.get_name ()) {
                         setup_monitor (id);
                     }
@@ -78,7 +78,7 @@
          * @brief Get the path where the files related to the given ID
          * are stored.
          */
-        internal string get_id_path (int id) {
+        internal string get_id_path (int64 id) {
             string path = Path.build_filename (resource_manager.get_filestore_dir (),
                                                 id.to_string ());                      
                                                 
@@ -100,7 +100,7 @@
          * @brief Setup a FileMonitor on the given directory ID, so we
          * may check for files created in there.
          */
-        private void setup_monitor (int id) {
+        private void setup_monitor (int64 id) {
             if (monitored_ids.find (id) != null) {
                 return;
             }
@@ -129,7 +129,7 @@
          * @brief Get the list of files associated to an ID.
          * This may even be an empty List.
          */
-        public GLib.List<FileObject> get_files (int id) {
+        public GLib.List<FileObject> get_files (int64 id) {
             // Get the local data directory
             string this_id_path = get_id_path (id);
             File d = File.new_for_path (this_id_path);
@@ -143,7 +143,6 @@
             try {
                 FileEnumerator enumerator = d.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, FileQueryInfoFlags.NONE);
             
-            
                 FileInfo info;
                 while ((info = enumerator.next_file ()) != null) {
                     results.append (new FileObject (this, id,
@@ -159,7 +158,7 @@
         /**
          * @brief Store a filed called filename in the FileStore.
          */
-        public string store_file (int id, string filename) {
+        public string store_file (int64 id, string filename) {
             // Source file
             File source_file = File.new_for_path (filename);
             
@@ -193,7 +192,7 @@
         /**
          * @brief Remove a file from the store.
          */
-        public void remove_file (int id, string filename) {
+        public void remove_file (int64 id, string filename) {
             FileUtils.remove (Path.build_filename (resource_manager.get_filestore_dir (),
                                                    id.to_string (), filename));
                                                                

=== modified file 'libclinica/FindEntry.vala'
--- libclinica/FindEntry.vala	2011-09-22 19:27:52 +0000
+++ libclinica/FindEntry.vala	2012-02-23 21:39:18 +0000
@@ -1,3 +1,23 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ *            Gianmarco Brocchi <brocchi@xxxxxxxxxxxxxxxxxxxx>
+ */
+
 using Gtk;
 
 namespace Clinica {

=== modified file 'libclinica/MedicineDetailDialog.vala'
--- libclinica/MedicineDetailDialog.vala	2011-12-19 06:28:10 +0000
+++ libclinica/MedicineDetailDialog.vala	2012-02-23 21:39:18 +0000
@@ -1,3 +1,22 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+
 using Gtk;
 
 namespace Clinica {

=== modified file 'libclinica/MedicineSearchEngine.vala'
--- libclinica/MedicineSearchEngine.vala	2011-12-09 17:28:05 +0000
+++ libclinica/MedicineSearchEngine.vala	2012-02-23 21:39:18 +0000
@@ -1,3 +1,22 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+ 
 namespace Clinica {
 
     public interface MedicineSearchEngine : UserInterfaceActivatable {

=== modified file 'libclinica/MedicineSearchPage.vala'
--- libclinica/MedicineSearchPage.vala	2012-01-29 10:39:56 +0000
+++ libclinica/MedicineSearchPage.vala	2012-02-23 21:39:18 +0000
@@ -1,3 +1,22 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+
 using Gtk;
 
 namespace Clinica {

=== modified file 'libclinica/MedicineTreeView.vala'
--- libclinica/MedicineTreeView.vala	2011-11-28 15:39:30 +0000
+++ libclinica/MedicineTreeView.vala	2012-02-23 21:39:18 +0000
@@ -1,3 +1,22 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+
 using Gtk;
 
 namespace Clinica {

=== modified file 'libclinica/Patient.vala'
--- libclinica/Patient.vala	2011-11-03 16:41:02 +0000
+++ libclinica/Patient.vala	2012-02-23 21:39:18 +0000
@@ -15,173 +15,48 @@
  *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
  *
  *   Authors: Leonardo Robol <leo@xxxxxxxx>
- *            Gianmarco Brocchi <brocchi@xxxxxxxxxxxxxxxxxxxx>
  */
- 
- using Gee;
- using Sqlite;
- 
- namespace Clinica {
+
+namespace Clinica {
  
     public enum Gender {
         MALE,
         FEMALE,
     }
-    
-    public class PatientIterator : SqlDataIterator {
-		private ResourceManager resource_manager;
-        public PatientIterator (ResourceManager resources) {
-            base (resources.db, resources.patient_table);
-            resource_manager = resources;
-        }
-        
-        public new PatientIterator iterator () { return this; }
-        
-        public new Patient get () {
-            return new Patient.with_id (resource_manager, base.get ());
-        }
-    }
- 
-    /**
-     * @brief A Patient object represent a person
-     * whose data are stored in the database (or
-     * are going to be stored soon).
-     */
-    public class Patient : SqlDataType {
-    
-        /**
-         * @brief Doctor associated to this patient. 
-         */
-        private Doctor? _doctor;
-        public Doctor? doctor {
-        	get {
-        		/* Always reload the doctor to make edits available immediately */
-        		if (get_integer ("doctor") == -1)
-        		    return null;
-          		this._doctor = new Doctor.with_id (resource_manager, get_integer ("doctor"));
-        		return this._doctor;
-        	}
-        	set {
-        		this._doctor = value;
-        		if (_doctor == null)
-        		    set_integer ("doctor", -1);
-                else
-            		set_integer("doctor", value.get_id ());
-        	}
-        }
-        
-        /* FIELDS */
-        public string given_name {
-        	get { return get_text ("given_name"); }
-        	set { set_text ("given_name", value); }
-        }
-        
-        public string surname {
-        	get { return get_text ("surname"); }
-			set { set_text ("surname", value); }
-        }
-        
-        private DateTime _birth_date;
-        public DateTime birth_date {
-        	get {
-        		_birth_date = get_date ("birth_date");
-        		return _birth_date;
-        	}
-        	set { 
-        		_birth_date = value;
-        		set_date ("birth_date", _birth_date); 
-        	}
-        }
-        
-        public Gender gender {
-        	get { 
-        		if (get_text("gender") == "MALE")
-        			return Gender.MALE;
-        		else
-        			return Gender.FEMALE;
-        	}
-        	set {
-        		if (value == Gender.MALE)
-        			set_text("gender", "MALE");
-        		else
-        			set_text("gender", "FEMALE");
-        	}
-        }
-        
-        public string phone {
-        	get { return get_text ("phone"); }
-        	set { set_text ("phone", value); }
-        }
-        
-        public string residence_address {
-        	get { return get_text ("residence_address"); }
-        	set { set_text ("residence_address", value); }
-        }
-        
-        public string identification_code {
-        	get { return get_text ("identification_code"); }
-        	set { set_text ("identification_code", value); }
-        }
-        
-        
-		private ResourceManager resource_manager;
-    
-        /**
-         * @brief Create a new patient
-         */
-        public Patient (ResourceManager resources, Doctor? doctor) {
-            base (resources.db);
-            resource_manager = resources;
-            table_name = resources.patient_table;
-            error.connect ((t,l) => resources.error_callback(t,l));
-            
-            add_text_field ("given_name");
-            add_text_field ("surname");
-            add_date_field ("birth_date");
-            add_text_field ("gender");
-            add_text_field ("phone");
-            add_text_field ("residence_address");
-            add_text_field ("identification_code");
-            add_integer_field ("doctor");
-
-            this.doctor = doctor;
-                
-            init_resources ();
-        }
-        
-        public Patient.with_id (ResourceManager resources, int ID) {
-            this (resources, null);
-            load (ID);
-            if (doctor != null)
-            {   
-                doctor = new Doctor.with_id (resources, get_integer ("doctor"));
-            }
-        }
-        
-        public static new PatientIterator all (ResourceManager resources) {
-            return new PatientIterator (resources);
-        }
+
+    public class Patient : Object {
+    
+        public DataProvider? provider = null; 
+    
+        public int64 id { get; set; default = 0; }
+    
+        public string given_name { get; set; }
+        
+        public string surname { get; set; }
+
+        public DateTime birth_date { get; set; }
+        
+        public Gender gender { get; set; }
+        
+        public string phone { get; set; }
+        
+        public string residence_address { get; set; }
+        
+        public string identification_code { get; set; }
+        
+        public Doctor doctor { get; set; }
         
         public string get_complete_name () {
         	return string.join (" ", this.given_name, this.surname);
         }
-
-		public int64 get_age () {
-			DateTime today = new DateTime.now_utc ();
-			var diff = today.difference (this.birth_date);
-
-			/* TimeSpan seems not to work.. :( */
-			return (diff / 31557600000000);
-		}
-		
-		/**
-		 * @brief Get the visit IDs for the selected patient.
-		 * Actual visits can then be retrieved with 
-		 * var visit = new Visit (ID);
-		 */
-		public GLib.List<int> get_visit_ids () {
-			return associated_ids (resource_manager.visits_table, "patient");
-		}
+        
+        public VisitIterator visits (DateTime? start = null, DateTime? end = null) {
+            if (provider == null)
+                return new EmptyVisitIterator ();
+            else
+                return provider.visits (this, start, end);
+        }
+    
     }
- 
- }
+
+}

=== modified file 'libclinica/PatientEditor.vala'
--- libclinica/PatientEditor.vala	2012-02-02 07:26:45 +0000
+++ libclinica/PatientEditor.vala	2012-02-23 21:39:18 +0000
@@ -405,8 +405,10 @@
             	
             	/*  Save the new patient, creating a new one if this is a new patient, or
             	 *  reusing the existing one if we are only modifying a patient. */
-            	if (existing_patient == null)
-	            	created_patient = new Patient (resource_manager, selected_doctor);
+            	if (existing_patient == null) {
+	            	created_patient = new Patient ();
+	            	created_patient.doctor = selected_doctor;
+	            }
 	            else
 					created_patient = existing_patient;
 					
@@ -443,15 +445,7 @@
 	            else
 	            	created_patient.gender = Gender.FEMALE;
 	            
-            	created_patient.save ();
-            	
-            	// If this was an existing patient we need to reload it in the patient
-            	// list store, otherwise we can just add it
-            	if (existing_patient != null) {
-            		resource_manager.patient_list_store.reload_patient (created_patient);
-            	} else {
-	            	resource_manager.patient_list_store.add_patient (created_patient);
-	            }
+            	resource_manager.data_provider.save_patient (created_patient);
             	
                 return Response.SAVE;
             }

=== modified file 'libclinica/PatientEditorActivatable.vala'
--- libclinica/PatientEditorActivatable.vala	2011-09-22 19:27:52 +0000
+++ libclinica/PatientEditorActivatable.vala	2012-02-23 21:39:18 +0000
@@ -1,3 +1,22 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+
 namespace Clinica {
 
     /**

=== modified file 'libclinica/PatientListStore.vala'
--- libclinica/PatientListStore.vala	2011-09-22 19:27:52 +0000
+++ libclinica/PatientListStore.vala	2012-02-23 21:39:18 +0000
@@ -53,10 +53,20 @@
             
             /* Asynchronous loading of patients */
             Idle.add(() => {
-		        foreach (Patient p in Patient.all (resource_manager)) {
-		        	add_patient (p);
+		        foreach (Patient p in resource_manager.data_provider.patients ()) {
+		        	add_patient (p.id);
 		        }
 		        
+		        /* Setup callbacks to add or remove patient */
+		        resource_manager.data_provider.patient_added.connect (
+		            (id) => add_patient (id));
+		        resource_manager.data_provider.patient_changed.connect (
+		            (id) => reload_patient (id));
+		        resource_manager.data_provider.patient_removed.connect ((id) => {
+		            TreeIter iter = id_to_iter (id);
+		            remove (iter);
+		         });
+		        
 		        /* We don't need to reiterate this function any more */
 		        return false;
 		    });
@@ -65,10 +75,11 @@
         /**
          * @brief Append the given patient to the liststore
          */
-        public void add_patient (Patient p) {
+        private void add_patient (int64 id) {
+            Patient p = resource_manager.data_provider.get_patient (id);
         	TreeIter it;
             append (out it);
-            set_value (it, Field.PATIENT,    p);
+            set_value (it, Field.PATIENT,    p);    
             set_value (it, Field.GIVEN_NAME, p.given_name);
             set_value (it, Field.SURNAME,    p.surname);
             set_value (it, Field.COMPLETE_NAME, p.get_complete_name ());
@@ -78,7 +89,8 @@
 	     * @brief Reload information about patient p that
 	     * should be already present in the database
 	     */
-	    public void reload_patient (Patient p) {
+	    private void reload_patient (int64 id) {
+	        Patient p = resource_manager.data_provider.get_patient (id);
 	    	TreeIter iter;
 	    	Value patient;
 	    	
@@ -88,7 +100,7 @@
 	    	
 	    	do {
 	    		get_value (iter, Field.PATIENT, out patient);
-	    		if ((patient as Patient).get_id () == p.get_id ()) {
+	    		if ((patient as Patient).id == p.id) {
 	    			set_value(iter, Field.PATIENT, p);
 	    			set_value(iter, Field.GIVEN_NAME, p.given_name);
 	    			set_value(iter, Field.SURNAME, p.surname);
@@ -101,63 +113,19 @@
 	    	assert_not_reached ();
 	    }
 	    
-	    /**
-	     * @brief Return a list of treeiters pointing to the patients
-	     * of the given doctor. 
-	     */
-	    public List<TreeIter?> get_patients_of (Doctor doc) {
-	    	Value value;
-	    	var iters = new List<TreeIter?> ();
-	    	TreeIter it;
-	    	Patient p;
-	    	
-	    	if (!get_iter_first (out it)) {
-	    		return iters;
-	    	}
-	    	do {
-	    		get_value (it, Field.PATIENT, out value);
-	    		p = value as Patient;
-	    		if (p.doctor.get_id () == doc.get_id ()) {
-	    			iters.append (it);
-	    		} 
-	    	} while (iter_next(ref it));
-	    	
-	    	return iters;
-	    }
-	    
-	    public TreeIter patient_to_iter (Patient p) {
+	    private TreeIter id_to_iter (int64 id) {
 	    	TreeIter it;
 	    	Value patient;
 	    	if (!get_iter_first (out it))
 				error(_("Patients database seems corrupted. This is likely to be a bug in the application"));
 	    	do {
 	    		get_value (it, Field.PATIENT, out patient);
-	    		if ((patient as Patient).get_id () == p.get_id ()) {
+	    		if ((patient as Patient).id == id) {
 	    			return it;
 	    		}
 	    	} while (iter_next (ref it));
 	    	
 	    	assert_not_reached ();
 	    }
-	    
-	    public void remove_patient (Patient p) {
-	    	TreeIter p_iter = patient_to_iter (p);
-	    	remove_patient_from_iter (p_iter);
-	    }
-	    
-	    public void remove_patient_from_iter (TreeIter it) {
-	    	Value patient;
-	    	get_value (it, Field.PATIENT, out patient);
-	    	
-	    	var visits = resource_manager.visit_list_store.get_visits_of (patient as Patient);
-	    	
-	    	foreach (TreeIter v_it in visits) {
-	    		resource_manager.visit_list_store.remove_visit_from_iter (v_it);
-	    	}
-	    	
-	    	/* Actually remove the patient */
-	    	(patient as Patient).remove ();
-	    	remove (it);
-	    }
 	}
 }

=== modified file 'libclinica/PatientListView.vala'
--- libclinica/PatientListView.vala	2012-01-31 08:10:13 +0000
+++ libclinica/PatientListView.vala	2012-02-23 21:39:18 +0000
@@ -135,10 +135,7 @@
             /*  Cast patient and update database data */
             patient = value as Patient;
             patient.given_name = new_text;
-            patient.save ();
-            
-            /*  Update UI */
-            resource_manager.patient_list_store.reload_patient (patient);
+            resource_manager.data_provider.save_patient (patient);
         }
         
         private void on_surname_cell_edited (CellRenderer renderer, string path, string new_text) {
@@ -155,10 +152,7 @@
             /*  Set new data in the Patient, save and update treeview */
             patient = value as Patient;
             patient.surname = new_text;
-            patient.save ();
-            
-            /*  Update UI */
-            resource_manager.patient_list_store.reload_patient (patient);
+            resource_manager.data_provider.save_patient (patient);
         }
         
         /**
@@ -189,8 +183,17 @@
         		TreeIter it;
 				sortable_model.convert_iter_to_child_iter (out it, iter);
         		filtered_store.convert_iter_to_child_iter (out iter, it);
-		    	/* Delete patient from the database and from the store*/
-		    	store.remove_patient_from_iter (iter);
+        		
+		    	/* Delete patient from the database */
+		    	Value value;
+		    	store.get_value (iter, PatientListStore.Field.PATIENT, out value);
+		    	
+		    	/* Removing the visits associated with this patient */
+		    	foreach (Visit visit in (value as Patient).visits ()) {
+		    	    resource_manager.data_provider.remove_visit (visit);
+		    	}
+		    	
+		    	resource_manager.data_provider.remove_patient (value as Patient);
 		    }
     	}
     	

=== modified file 'libclinica/PluginEngine.vala'
--- libclinica/PluginEngine.vala	2011-09-22 19:27:52 +0000
+++ libclinica/PluginEngine.vala	2012-02-23 21:39:18 +0000
@@ -1,3 +1,22 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+
 namespace Clinica {
 
     public class PluginEngine : Peas.Engine {

=== modified file 'libclinica/ResourceManager.vala'
--- libclinica/ResourceManager.vala	2012-02-02 07:26:45 +0000
+++ libclinica/ResourceManager.vala	2012-02-23 21:39:18 +0000
@@ -78,6 +78,14 @@
         public EventListStore event_list_store;
         
         /**
+         * @brief This is the object used to retrieve all the data
+         * about patients and which events should be connected
+         * to the views to make them react to changes in the database
+         * or whatever the data source is.
+         */
+        internal DataProvider data_provider;
+        
+        /**
          * @brief Reference to a user interface
          */
         public UserInterface user_interface;
@@ -98,24 +106,13 @@
          * @brief Local configuration directory
          * obtained at runtime.
          */
-        private string local_config_directory;
+        internal string local_config_directory;
         
         /**
          * @brief Local data directory obtained 
          * at runtime.
          */
-        private string local_data_directory;
-        
-        /**
-         * @brief Database path.
-         */
-        private string database_path;
-        
-        /**
-         * @brief SQLite database with data and
-         * configurations.
-         */
-        public Database db;
+        internal string local_data_directory;
         
         /**
          * @brief The file store used to retrieve the data associated 
@@ -135,12 +132,20 @@
          */
         internal GLib.List<unowned MedicineSearchEngine> medicine_search_engines;
         
+        /** 
+         * @brief List containing the available DataProviders that 
+         * can be used to retrieve data in Clinica. 
+         */
+        internal List<unowned DataProvider> data_providers;
+        
         /**
          * @brief A pointer to the patient that is been dragged. Should
          * be set on drag_begin by the treeview and reset to null by the
          * drag destination handler. 
          */
 		internal Patient? dragging_patient = null;
+		
+		private Peas.ExtensionSet core_set;
         
         /**
          * @brief Path to the UI files directory
@@ -160,9 +165,8 @@
         /** SIGNALS **/
         public signal void medicine_search_engines_added (MedicineSearchEngine engine);
         public signal void medicine_search_engines_removed (MedicineSearchEngine engine);
-        
-        private const string [] supported_db_versions = { "0.1", "0.2" };
-        private const string db_version = "0.2";
+        public signal void data_provider_added (DataProvider provider);
+        public signal void data_provider_removed (DataProvider provider);
     
         public ResourceManager (Gtk.Application? application, 
                                 string program_name = "clinica", 
@@ -198,68 +202,11 @@
                 DirUtils.create_with_parents (local_data_directory, -1);
             }
             
-            /* Set database path and check if a database exists in the old location, 
-             * if that's the case move it to the new one. */
-            check_database_path ();
-            
             /* Check if the directory for the FileStore exists */
             File fsd = File.new_for_path (get_filestore_dir ());
             if (!fsd.query_exists ())
                 DirUtils.create_with_parents (get_filestore_dir (), -1);
             file_store = new FileStore (this);
-                                                 
-            /* Read database version if existant, saved actual version otherwise.
-             * This may be used in future to perform one-time upgrade of the database */
-            var version_db_file = Path.build_filename (local_config_directory, 
-            										   ".clinica_db_version");
-            										   
-        	if (!FileUtils.test (version_db_file, FileTest.IS_REGULAR)) {
-        		/* Create the file with the version of the database */
-        		try {
-	        		FileUtils.set_contents(version_db_file, db_version);
-	        	} catch (Error e) {
-	        		error (_("Error creating some configuration files, check permission on %s".printf(version_db_file)));
-	        	}
-        	}
-        	else {
-        		string content;
-        		try {
-        			FileUtils.get_contents(version_db_file, out content);
-        		} catch (Error e) {
-        			error (_("Error reading some configuration files, check permission on %s".printf(version_db_file)));
-        		}
-        		
-        		bool upgraded_correcty = true;
-        		if (db_version != content) {
-        		    /* Ask the user if he really wants to upgrade */
-        		    if (!ask_for_upgrade()) {
-        		        debug ("The user doesn't want to upgrade, exiting.");
-        		        Posix.exit (0);
-        		    }
-        		
-        		    upgraded_correcty = false;
-        		    /* Try to determine if the version of the local database is supported */
-        		    if (content in supported_db_versions) {
-        		        if (upgrade_database (content)) {
-        		            upgraded_correcty = true;
-        		            try {
-            		            FileUtils.set_contents (version_db_file, db_version);
-            		        } catch (GLib.Error e) {
-            		            error (_("Failure while settings new database version to %s").printf (db_version));
-                            }
-        		        } else {
-        		            error (_("Failure while upgrading database"));
-        		        }
-        		    }
-        		    else
-        			    error (_("Version of the database is not compatible"));
-        		}
-        		
-        		if (!upgraded_correcty) {
-      		        debug ("Upgrade failed, exiting.");
-        		    Posix.exit (1);
-        		}
-        	}
                                                 
             /* Find prefix */
             prefix = "/usr/local";
@@ -312,6 +259,11 @@
             /* Create configuration */
             settings = new Settings (this);
             
+            /* SqliteDataProvider must always be the first DataProvider
+             * in the list */
+            data_providers = new List<unowned DataProvider> ();
+            register_data_provider (new SqliteDataProvider (this));
+            
             /* Load all extensions found... this is quite ugly, but an
              * interface to select loaded plugins is still needed. 
              * For now, do it in the idle cycle to allow clinica to start
@@ -320,64 +272,14 @@
                  load_plugins.begin ();
         }
         
-        private bool ask_for_upgrade () {
-            var mb = new MessageDialog (null,
-                DialogFlags.DESTROY_WITH_PARENT |
-                DialogFlags.MODAL,
-                MessageType.QUESTION,
-                ButtonsType.YES_NO,
-                "%s", "Database upgrade");
-            mb.format_secondary_markup (_("This is a version of Clinica newer than the one that created the\npatients database installed on the system.\nUsing this version requires upgrading the database, and\n<b>the old version will not be able to use it anymore</b>.\nDo you wish to perform this one-time upgrade?\n"));
-            mb.set_title (_("Upgrade database"));
-            if (mb.run () == ResponseType.YES) {
-                mb.destroy ();
-                return true;
-            }
-            else {
-                mb.destroy ();
-                return false;
-           }
-        }
-        
-        /**
-         * @brief Check if the database is in the right path. If it is not there
-         * move it and the set database_path.
-         */
-        private void check_database_path () {
-            database_path = Path.build_filename (local_data_directory,
-                                                 "clinica.db");
-            File db_file = File.new_for_path (database_path);
-            if (!db_file.query_exists ()) {
-                File old_db_file = File.new_for_path (Path.build_filename (local_config_directory, 
-                        "clinica.db"));
-                if (old_db_file.query_exists ()) {
-                
-                    var mb = new MessageDialog (null, DialogFlags.DESTROY_WITH_PARENT | DialogFlags.MODAL,
-                        MessageType.QUESTION, ButtonsType.YES_NO, "%s", _("Database needs to be moved"));
-                    mb.format_secondary_markup (_("An older version of clinica has been detected and the old database has to be moved\nto a new location to continue.\n<b>The older version of clinica won't work anymore with this setup</b>.\nDo you still want to continue?"));
-                    if (mb.run () != Gtk.ResponseType.YES) {
-                        mb.destroy ();
-                        Posix.exit (1);
-                    }
-                    
-                    mb.destroy ();
-                
-                    debug ("Moving old database to its new location (starting from clinica 0.2.9)");
-                    try {
-                        old_db_file.copy (db_file, FileCopyFlags.ALL_METADATA);
-                        FileUtils.remove (old_db_file.get_path ());
-                    } catch (GLib.Error e) {
-                        error (_("Error while transferring the database to the new default location for clinica >= 0.2.9"));
-                    }
-                }
-            }
-        }
+        private extern Peas.ExtensionSet setup_extension_set (PluginEngine engine);
         
         /**
          * @brief Instantiate the plugin engine and load
          * all the plugins present in the directory
          */
         public async void load_plugins () {
+        
             /* Setup plugin engine */
             plugin_engine = new PluginEngine (this);   
             plugin_engine.enable_loader ("python");
@@ -396,6 +298,34 @@
                     debug ("Plugin %s found but disabled".printf (info.get_name ()));
                 }
             }
+            
+            /* Setup the CoreActivatable extension set, so new DataProviders will be available */
+            core_set = setup_extension_set (plugin_engine);
+                
+            /* Create the store that will be attached to the data provider selected 
+             * above */         
+            doctor_list_store = new DoctorListStore (this);
+            patient_list_store = new PatientListStore (this);
+            visit_list_store = new VisitListStore (this);
+            event_list_store = new EventListStore (this);
+        }
+        
+        public void register_data_provider (DataProvider provider) {
+            data_providers.append (provider);
+            data_provider_added (provider);
+            
+            if (data_provider == null)
+                data_provider = provider;
+                
+            if (provider.get_name () == settings.get_string ("data-provider"))
+                data_provider = provider;
+        }
+        
+        public void unregister_data_provider (DataProvider provider) {
+            if (provider == data_provider) {
+                data_provider = data_providers.nth_data (0);
+                settings.set_string ("data-provider", "");
+            }
         }
         
         public void register_medicine_search_engine (MedicineSearchEngine engine) {
@@ -440,6 +370,10 @@
             }
         }
         
+        public string get_data_path () {
+            return local_data_directory;
+        }
+        
         /**
          * @brief Get the directory in which the FileStore can store its files.
          */
@@ -447,109 +381,6 @@
             return Path.build_filename (local_data_directory, "filestore");
         }
         
-        private bool upgrade_database (string db_version) {
-            /* Try to open the database first */
-            if (!(Database.open (database_path, out db) == OK)) {
-                error (_("Error upgrading database, please check your installation"));
-            }
-            
-            string sql;
-            Statement stmt;
-            int rc;
-            
-            /* Performing upgrade from 0.1 */
-            if (db_version == "0.1") {
-                /* We need to create the new table for the events */
-               sql = "CREATE TABLE IF NOT EXISTS events (id INTEGER PRIMARY KEY, title TEXT, description TEXT, venue TEXT, patient INTEGER, visit INTEGER, date TEXT);";
-               db.prepare (sql, -1, out stmt, null);
-               rc = stmt.step ();
-               
-               if (rc != DONE) {
-                   error (_("Error upgrading the database from version 0.1 to 0.2, sqlite exit code: %d".printf (rc)));
-                   return false;
-               } else {
-                   db_version = "0.2";
-               }
-            }
-            
-            return true;
-        }
-        
-        /**
-         * @brief Check that all the resources needed by Clinica
-         * are actually available, and if they are not create them.
-         */
-        public void initResources () {
-            int rc;
-            Statement stmt;
-            string sql;
-            
-            /* Open database and, if it does not exists, create it */
-            if (!(Database.open (database_path, out db) == OK)) {
-                error ("Error opening database.");
-            };
-            
-            /* Check if the required tables exists */
-            sql = "SELECT * from sqlite_master WHERE type='table';";
-            db.prepare (sql, -1, out stmt, null);
-            rc = stmt.step ();
-            
-            if (rc == DONE) {
-                /* That means no tables in the database */
-                initDatabase ();
-            }
-
-            /* Load stores */
-            doctor_list_store = new DoctorListStore (this);
-            patient_list_store = new PatientListStore (this);
-            visit_list_store = new VisitListStore (this);
-            event_list_store = new EventListStore (this);
-        }
-        
-        
-        /**
-         * @brief Init the database with the required tables
-         */
-        private void initDatabase () {
-            Statement stmt; 
-            string sql;
-            string err_msg;
-            
-            /* Create config table */
-            sql = "CREATE TABLE config (id INTEGER PRIMARY KEY, " +
-                  "key TEXT, value TEXT);";
-            db.prepare (sql, -1, out stmt, null);
-            if (!(stmt.step () == DONE)) {
-                err_msg = db.errmsg ();
-                error ("Error creating config structure in the Database: "
-                + err_msg);
-            }
-        }            
-        
-        /**
-         * @brief Return a Doctor object associated to the given ID
-         */
-        public Doctor getDoctor (int ID) {
-            Doctor doctor = new Doctor.with_id (this, ID);
-            return doctor;
-        }
-        
-        /**
-         * @brief Return a Patient object associated to the given ID
-         */
-        public Patient getPatient (int ID) {
-            Patient p = new Patient.with_id (this, ID);
-            return p;
-        }
-        
-        /**
-         * @brief Return a Visit object associated to the given ID
-         */
-        public Visit getVisit (int ID) {
-            Visit visit = new Visit.with_id (this, ID);
-            return visit;
-        }
-        
         
     }
    

=== modified file 'libclinica/Service.vala'
--- libclinica/Service.vala	2012-01-26 17:41:05 +0000
+++ libclinica/Service.vala	2012-02-23 21:39:18 +0000
@@ -39,12 +39,12 @@
          * @brief Return a lists of patients id whose name
          * match the given string.
          */
-        public int [] patients_filter (string filter) {
+        public int64 [] patients_filter (string filter) {
             string lfilter = filter.down();
-            int [] patients = {};
-            foreach (var patient in Patient.all (resource_manager)) {
+            int64 [] patients = {};
+            foreach (var patient in resource_manager.data_provider.patients ()) {
                 if (lfilter in patient.get_complete_name ().down ()) {
-                    patients += patient.get_id ();
+                    patients += patient.id;
                 }
             }
             

=== modified file 'libclinica/SettingsManager.vala'
--- libclinica/SettingsManager.vala	2012-01-29 10:39:56 +0000
+++ libclinica/SettingsManager.vala	2012-02-23 21:39:18 +0000
@@ -69,6 +69,9 @@
             var mse_selector = new MedicineSearchEngineSelector (resource_manager);
             structure_vbox.pack_start (mse_selector, false);
             
+            var dp_selector = new DataProviderSelector (resource_manager);
+            structure_vbox.pack_start (dp_selector, false);
+            
             /* Add structure vbox to the first page of the Notebook */
             var sv_alignment = new Alignment (0.5F, 0.5F, 1.0F, 1.0F);
             sv_alignment.set_padding (6,6,6,6);
@@ -166,4 +169,65 @@
             }
         }
     }
+        
+        
+    public class DataProviderSelector : HBox {
+        
+        private ResourceManager resource_manager { get; set; }
+        private ComboBoxText    data_provider_selector;
+        
+        public DataProviderSelector (ResourceManager resources) {
+            GLib.Object (homogeneous: false, spacing: 6);
+            resource_manager = resources;
+            var label = new Label (_("Select the data provider\nused to retrieve data"));
+            label.set_alignment (0.0F, 0.5F);
+            pack_start (label);
+            
+            /* Create the combobox and keep a track of its position in the array. */
+            data_provider_selector = new ComboBoxText ();
+            refresh_provider_list ();
+            resource_manager.data_provider_added.connect ((provider) => refresh_provider_list ());
+            resource_manager.data_provider_removed.connect ((provider) => refresh_provider_list ());
+            pack_start (data_provider_selector, false, true);
+            data_provider_selector.changed.connect (on_data_provider_selector_changed);
+        }
+        
+        private void on_data_provider_selector_changed () {
+            string? active_id = data_provider_selector.get_active_id ();
+            if (active_id == null)
+                return;
+            var index = int.parse (active_id);
+            resource_manager.data_provider = 
+                resource_manager.data_providers.nth_data (index);
+            resource_manager.settings.set_string ("data-provider", 
+                resource_manager.data_provider.get_name ());
+        }
+        
+        private void refresh_provider_list () {
+            int i = 0;
+            data_provider_selector.remove_all ();
+            
+            /* If no preference is set set the first engine as selected */
+            if (resource_manager.settings.get_string ("data-provider") == "") {
+                if (resource_manager.data_providers.length () != 0) {
+                    resource_manager.data_provider = 
+                        resource_manager.data_providers.nth_data (0);
+                    resource_manager.settings.set_string ("data-provider", 
+                        resource_manager.data_provider.get_name ());
+                }
+            }
+            
+            /* Load engines in the liststore */
+            foreach (var provider in resource_manager.data_providers) {
+                data_provider_selector.append ("%d".printf (i++), provider.get_name ());
+                if (resource_manager.settings.get_string ("data-provider") == provider.get_name ()) {
+                    debug ("Loading data provider: %s", provider.get_name ());
+                    resource_manager.data_provider = provider;
+                }
+                if (provider == resource_manager.data_provider) {
+                    data_provider_selector.set_active (i - 1);
+                }
+            }
+        }
+    }
 }

=== removed file 'libclinica/SqlDataType.vala'
--- libclinica/SqlDataType.vala	2011-10-04 12:15:09 +0000
+++ libclinica/SqlDataType.vala	1970-01-01 00:00:00 +0000
@@ -1,397 +0,0 @@
-/*
- *   This file is part of Clinica.
- *
- *   Clinica is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   (at your option) any later version.
- *
- *   Clinica is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
- *
- *   Authors: Leonardo Robol <leo@xxxxxxxx>
- *            Gianmarco Brocchi <brocchi@xxxxxxxxxxxxxxxxxxxx>
- */
-
-using Sqlite;
-using Gee;
-
-namespace Clinica {
-
-    /**
-     * @brief Struct representing a column in the database.
-     */
-    public class SqlColumn {
-        public string  type;
-        public string  v;
-        
-        public SqlColumn (string type) {
-            this.type = type;
-        }
-    }
-    
-    public class SqlDataIterator : GLib.Object {
-
-        protected unowned Database db;
-        protected Statement stmt;
-
-        public SqlDataIterator (Database db, string table_name, string? order_by = null, bool desc = false) {
-            this.db = db;
-            if (order_by == null)
-                db.prepare (@"SELECT ID FROM $(table_name);", -1, out stmt, null);
-            else {
-                if (desc)
-                    db.prepare (@"SELECT ID FROM $(table_name) ORDER by $(order_by) DESC;", -1, out stmt, null);
-                else
-                    db.prepare (@"SELECT ID FROM $(table_name) ORDER by $(order_by);", -1, out stmt, null);
-            }
-        }
-        
-        public SqlDataIterator.with_like (Database db, string table_name, string? order_by = null, 
-            bool desc = false, string where_stmt) {
-            this.db = db;
-            
-            if (order_by == null)
-                db.prepare (@"SELECT ID FROM $(table_name) WHERE $(where_stmt);", -1, out stmt, null);
-            else {
-                if (desc)
-                    db.prepare (@"SELECT ID FROM $(table_name) WHERE $(where_stmt) ORDER by $(order_by) DESC;", -1, out stmt, null);
-                else
-                    db.prepare (@"SELECT ID FROM $(table_name) WHERE $(where_stmt) ORDER by $(order_by);", -1, out stmt, null);
-            }
-        }
-        
-        public SqlDataIterator iterator () {
-            return this;
-        }
-        
-        public bool next () {
-            return (stmt.step () == ROW);
-        }
-            
-        public new int get () {
-            return stmt.column_int (0);
-        }
-    }
-
-    /**
-     * @brief Interface representing an abstract data
-     * type interfaced to a SQLite database. 
-     */
-    public class SqlDataType : GLib.Object {
-    
-        /**
-         * @brief Signal emitted when an error eris
-         * encountered
-         */
-        public signal void error (string message);
-        
-        /**
-         * @brief The table name in the database. Must be set
-         * by the class implementing this interface.
-         */
-        public string table_name;
-        
-        /**
-         * @brief The database object used to interact with
-         * the sqlite database. It must be opened by the
-         * class implementing this interface. 
-         */
-        public unowned Database db;
-        
-        /**
-         * @brief Hash mapping column_name -> type, value.
-         */
-        public HashMap<string, SqlColumn?> columns;
-        
-        public SqlDataType (Database db) {
-            this.db = db;
-            columns = new HashMap<string, SqlColumn> ();
-            this.columns.set ("ID", new SqlColumn ("INTEGER PRIMARY KEY"));
-            set_integer ("ID", 0);
-        }
-        
-        public SqlDataType.with_id (Database db, int ID) {
-            this (db);
-            load (ID);
-        }
-        
-        protected void add_text_field (string name) {
-            this.columns.set (name, new SqlColumn ("TEXT"));
-        }
-        
-        protected void add_integer_field (string name) {
-            this.columns.set (name, new SqlColumn ("INTEGER"));
-        }
-        
-        protected void add_date_field (string name) {
-        	this.columns.set (name, new SqlColumn ("TEXT"));
-        }
-        
-        /**
-         * @brief Escape a string and surround it with
-         * double quotes ready to be inserted in the 
-         * database.
-         */
-        protected string quote (string str) {
-            return "\"" + str.escape ("") + "\"";
-        }
-        
-        /**
-         * @brief Initialize resource, i.e. open the database
-         * and check for missing tables.
-         */
-        protected void init_resources () {
-	        lock (db) {
-			    Statement stmt;
-			    
-			    /* Check if the table is present in the database and if it's
-			     * not, create it */
-			    db.prepare (@"SELECT * from sqlite_master WHERE name='$(table_name)';",
-			                -1, out stmt, null);
-			                
-			    if (stmt.step () == DONE) {
-			        init_database ();
-			    }
-		    }
-        }
-        
-        /**
-         * @brief Create table structure in the database.
-         */
-        protected void init_database () {
-            Statement stmt;
-            string sql = @"CREATE TABLE $(table_name) (";
-            foreach (Map.Entry<string, SqlColumn> e in columns.entries) {
-                sql += @"$(e.key) $(e.value.type), ";
-            }
-            
-            /* Remove last 2 characters ", " and add ); */
-            sql = sql[0:-2];
-            sql += ");";
-            
-            /* Execute query */
-            db.prepare (sql, -1, out stmt, null);
-            
-            if (stmt.step () != DONE) {
-                error (@"Error creating $(table_name) table in the database.");
-            }
-        }
-        
-        public string get_db_table_name () {
-            return this.table_name;
-        }
-        
-        public void set_text (string field, string val) {
-        	if (!columns.has_key (field)) {
-        		error (@"Error saving to field $(field) from table $(table_name)\n" + 
-        				"Selected field is not present in database");
-        		return;
-        	}
-            SqlColumn col = columns.get (field);
-            col.v = val;
-            columns.set (field, col);
-        }
-        
-        public unowned string get_text (string field) {
-        	if (!columns.has_key (field)) {
-        		error (@"Error loading from field $(field) from table $(table_name)\n" + 
-        				"Selected field is not present in database");
-        		return "";
-        	}
-            SqlColumn col = columns.get (field);
-            if (col.v != null)
-                return col.v;
-            else
-                return "";
-        }
-        
-        public unowned int get_integer (string field) {
-        	if (!columns.has_key (field)) {
-        		error (@"Error loading from field $(field) from table $(table_name)\n" + 
-        				"Selected field is not present in database");
-        		return 0;
-        	}
-            SqlColumn col = columns.get (field);
-            return int.parse (col.v);
-        }
-        
-        public DateTime get_date (string field) {
-        	if (!columns.has_key (field)) {
-        		error (@"Error loading from field $(field) from table $(table_name)\n" + 
-        				"Selected field is not present in database");
-        		return new DateTime.now_utc ();
-        	}
-        	SqlColumn col = columns.get (field);
-        	string [] fields = col.v.split(" ");
-        	
-        	int year = int.parse (fields[0]);
-        	int month = int.parse (fields[1]);
-        	int day = int.parse (fields[2]);
-        	int hour = int.parse (fields[3]);
-        	int minute = int.parse (fields[4]);
-        	int seconds = int.parse (fields[5]);
-        	
-        	if (year < 1 || year > 9999 || 
-        		month < 1 || month > 12 ||
-        		day < 1 || day > 31 ||
-        		minute < 0 || minute > 59 ||
-        		seconds < 0 || seconds > 59)
-        		return new DateTime.now_local ();
-        	
-        	return new DateTime.local (year, month, day, hour, minute, seconds);
-        }
-        
-        public void set_date (string field, DateTime date) {
-        	if (!columns.has_key (field)) {
-        		error (@"Error saving tofield $(field) from table $(table_name)\n" + 
-        				"Selected field is not present in database");
-        		return;
-        	}
-        	SqlColumn col = columns.get (field);
-        	col.v = datetime_to_string (date);
-        }
-        
-        public static string datetime_to_string (DateTime date) {
-            return string.join(" ", 
-        		date.get_year ().to_string (), 
-        		"%.2d".printf (date.get_month ()), 
-        		"%.2d".printf (date.get_day_of_month()), 
-        		"%.2d".printf (date.get_hour ()), 
-        		"%.2d".printf (date.get_minute ()), 
-        		"%.2d".printf (date.get_second ()));
-        }
-        
-        public int get_id () {
-            return get_integer ("ID");
-        }
-        
-        public void set_integer (string field, int64 val) {
-        	if (!columns.has_key (field)) {
-        		error (@"Error saving tofield $(field) from table $(table_name)\n" + 
-        				"Selected field is not present in database");
-        		return;
-        	}
-            SqlColumn col = columns.get (field);
-            if (field == "ID" && val == 0)
-                col.v = "NULL";
-            else
-                col.v = val.to_string ();
-            columns.set (field, col);
-        }
-        
-        public new string get (string field) {
-            return get_text (field);
-        }
-        
-        public new void set (string field, string value) {
-            set_text (field, value);
-        }
-        
-        /**
-         * @brief Save changes permanently in the database
-         */
-        public void save () {
-            Statement stmt;
-            string sql = @"INSERT OR REPLACE INTO $(table_name) (";
-            foreach (Map.Entry<string, SqlColumn> e in columns.entries) {
-                sql += @"$(e.key), ";
-            }
-            
-            sql = sql[0:-2];
-            sql += ") VALUES (";
-
-            foreach (Map.Entry<string, SqlColumn> e in columns.entries) {
-                if (e.value.v != null) {
-                    if (e.value.type == "TEXT")
-                        sql += @"$(quote(e.value.v)), ";
-                    else
-                        sql += @"$(e.value.v), ";
-                }
-                else {
-                    sql += ", ";
-                }
-            }
-            
-            sql = sql[0:-2]; sql += ");";
-            db.prepare (sql, -1, out stmt, null);
-            if (stmt.step () != DONE) {
-                error (@"Error inserting values in the database $(table_name)\n Error $(db.errcode()): $(db.errmsg ())");
-            }
-            
-            /* If we save with ID set to 0 then the ID will be autodetermined
-             * by sqlite so we should get it back */
-            if (get_id () == 0) {
-            	set_integer("ID", db.last_insert_rowid());
-            }
-        }
-        
-        /**
-         * @brief Load data from database, overwriting local
-         * variables.
-         */
-        public void load (int ID = 0) {
-            if (ID == 0)
-                ID = get_integer ("ID");
-                
-            Statement stmt;
-            string sql = "SELECT ";
-            foreach (Map.Entry<string, SqlColumn> e in columns.entries) {
-                sql += @"$(e.key), ";
-            }
-            
-            sql = sql[0:-2];
-            sql += @" FROM $(table_name) WHERE ID=$(ID);";
-            
-            db.prepare (sql, -1, out stmt, null);
-            if (stmt.step () !=ROW) {
-                error (@"Error loading data from table $(table_name).");
-                return;
-            }
-            
-            int i = 0;
-            foreach (Map.Entry<string, SqlColumn> e in columns.entries) {
-            	if (e.value.type == "TEXT")
-            		e.value.v = stmt.column_text (i).compress ();
-            	else
-	                e.value.v = stmt.column_text (i);
-                i++;
-            }
-        }
-        
-        /**
-         * @brief Delete this item permanently from the database.
-         */
-        public void remove () {
-        	Statement stmt;
-        	string sql = @"DELETE from $(table_name) WHERE ID=$(get_id ());";
-        	
-        	db.prepare (sql, -1, out stmt, null);
-        	if (stmt.step () != DONE) {
-        		error (@"Error deleting item from the database $(table_name)");
-        	}
-        }
-        
-        /**
-         * @brief Find IDs of elements in ex_table (that is assumed to be a table
-         * associateed to another SqlDataType object and return a vector
-         * containing their IDs. 
-         */ 
-        public GLib.List<int> associated_ids (string ex_table, string foreign_key) {
-        	var ids = new GLib.List<int> ();
-        	Statement stmt;
-        	string sql = @"SELECT ID from $(ex_table) WHERE $(foreign_key)=$(get_id());";
-        	
-        	db.prepare (sql, -1, out stmt, null);
-        	while (stmt.step () == ROW) {
-        		ids.append (stmt.column_int (0));
-        	}
-        	return ids;
-        }
-    }
-}

=== added file 'libclinica/SqliteDataProvider.vala'
--- libclinica/SqliteDataProvider.vala	1970-01-01 00:00:00 +0000
+++ libclinica/SqliteDataProvider.vala	2012-02-23 21:39:18 +0000
@@ -0,0 +1,754 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+
+using Sqlite;
+using Gtk;
+
+namespace Clinica {
+
+    public class SqliteDataProvider : Object, DataProvider {
+    
+        public signal void error (string message);
+    
+        /**
+         * @brief Name of the table in the database where the visits
+         * will be stored. Please note that changing this will require
+         * a database upgrade, so should be handled correctly.
+         */
+        internal string visit_table = "visits";
+        
+        /**
+         * @brief Name of the table in the database where the patients
+         * will be stored. Please note that changing this will require
+         * a database upgrade, so should be handled correctly.
+         */
+        internal string patient_table = "patients";
+        
+        /**
+         * @brief Name of the table in the database where the doctors
+         * will be stored. Please note that changing this will require
+         * a database upgrade, so should be handled correctly.
+         */
+        internal string doctor_table = "doctors";
+        
+        /**
+         * @brief Name of the table in the database where the events
+         * will be stored. Please note that changing this will require
+         * a database upgrade, so should be handled correctly.
+         */
+        internal string event_table = "events";
+        
+        /**
+         * @brief The absolute path of the database (typically on Linux systems
+         * will be ~/.local/share/clinica/clinica.db.
+         */
+        private string database_path;
+        
+        /**
+         * @brief The ResourceManager of this instance of the Clinica Application.
+         */
+        private ResourceManager resource_manager { get; set; }
+        
+        /**
+         * @brief The Sqlite.Database object - this is used to interact with the database
+         * by the SqliteDataProvider and all the Sqlite*Iterator classes that are generated
+         * from here.
+         */
+        internal Database db;
+        
+        /**
+         * @brief An array containing the supported versione of the db. This should
+         * contain the value db_version and means that this SqliteProvider is capable
+         * of Database migration from any of these old version to the most recent one.
+         */
+        private const string [] supported_db_versions = { "0.1", "0.2" };
+        
+        /**
+         * @brief The version of the database that is in use now, or that should
+         * be used to compatbile with this SqliteDataProvider.
+         *
+         * Please note that Database version are not the same of Clinica versions.
+         * Typically the same clinica versions will use the same Database version,
+         * but the other way is not always true.
+         */
+        private const string db_version = "0.2";
+    
+    
+        public SqliteDataProvider (ResourceManager resources) {
+            resource_manager = resources;
+            error.connect ((t,l) => resource_manager.error_callback (t,l));
+            
+            /* Find the database in all the possible paths for the various
+             * versions of Clinica, and then possibly do un upgrade, querying
+             * the user if necessary. */
+            check_database_path ();
+            check_updates ();
+            
+            /* This is used to create the tables if they do not exists */
+            init_resources ();
+        }
+        
+        /**
+         * @brief Get the identifier for this DataProvider to be displayed
+         * to the user.
+         *
+         * It has not to be translated since it will be used to detect which
+         * will be used on startup.
+         */
+        public string get_name () { return "Local database"; }
+        
+        /**
+         * @brief Check if there is the need to upgrade the database from on of
+         * the supported version to the most recent one.
+         */
+        private void check_updates () {                    
+            /* Read database version if existant, saved actual version otherwise.
+             * This may be used in future to perform one-time upgrade of the database */
+            var version_db_file = Path.build_filename (resource_manager.local_config_directory, 
+            										   ".clinica_db_version");
+            										   
+        	if (!FileUtils.test (version_db_file, FileTest.IS_REGULAR)) {
+        		/* Create the file with the version of the database */
+        		try {
+	        		FileUtils.set_contents(version_db_file, db_version);
+	        	} catch (Error e) {
+	        		error (_("Error creating some configuration files, check permission on %s").printf (version_db_file));
+	        	}
+        	}
+        	else {
+        		string content;
+        		try {
+        			FileUtils.get_contents(version_db_file, out content);
+        		} catch (Error e) {
+        			error (_("Error reading some configuration files, check permission on %s".printf(version_db_file)));
+        		}
+        		
+        		bool upgraded_correcty = true;
+        		if (db_version != content) {
+        		    /* Ask the user if he really wants to upgrade */
+        		    if (!ask_for_upgrade()) {
+        		        debug ("The user doesn't want to upgrade, exiting.");
+        		        Posix.exit (0);
+        		    }
+        		
+        		    upgraded_correcty = false;
+        		    /* Try to determine if the version of the local database is supported */
+        		    if (content in supported_db_versions) {
+        		        if (upgrade_database (content)) {
+        		            upgraded_correcty = true;
+        		            try {
+            		            FileUtils.set_contents (version_db_file, db_version);
+            		        } catch (GLib.Error e) {
+            		            error (_("Failure while settings new database version to %s").printf (db_version));
+                            }
+        		        } else {
+        		            error (_("Failure while upgrading database"));
+        		        }
+        		    }
+        		    else
+        			    error (_("Version of the database is not compatible"));
+        		}
+        		
+        		if (!upgraded_correcty) {
+      		        debug ("Upgrade failed, exiting.");
+        		    Posix.exit (1);
+        		}
+        	}
+        }
+        
+        /**
+         * @brief This routine is used to ask confirmation to the user for the database
+         * upgrade. Since the upgrade will make the older version of clinica unusable, we
+         * should always ask before performing one.
+         */
+        private bool ask_for_upgrade () {
+            var mb = new MessageDialog (null,
+                DialogFlags.DESTROY_WITH_PARENT |
+                DialogFlags.MODAL,
+                MessageType.QUESTION,
+                ButtonsType.YES_NO,
+                "%s", "Database upgrade");
+            mb.format_secondary_markup (_("This is a version of Clinica newer than the one that created the\npatients database installed on the system.\nUsing this version requires upgrading the database, and\n<b>the old version will not be able to use it anymore</b>.\nDo you wish to perform this one-time upgrade?\n"));
+            mb.set_title (_("Upgrade database"));
+            if (mb.run () == ResponseType.YES) {
+                mb.destroy ();
+                return true;
+            }
+            else {
+                mb.destroy ();
+                return false;
+           }
+        }
+        
+        /**
+         * @brief Check if the database is in the right path. If it is not there
+         * move it and the set database_path.
+         */
+        private void check_database_path () {
+            database_path = Path.build_filename (resource_manager.local_data_directory,
+                                                 "clinica.db");
+            File db_file = File.new_for_path (database_path);
+            if (!db_file.query_exists ()) {
+                File old_db_file = File.new_for_path (Path.build_filename (resource_manager.local_config_directory, 
+                        "clinica.db"));
+                if (old_db_file.query_exists ()) {
+                
+                    var mb = new MessageDialog (null, DialogFlags.DESTROY_WITH_PARENT | DialogFlags.MODAL,
+                        MessageType.QUESTION, ButtonsType.YES_NO, "%s", _("Database needs to be moved"));
+                    mb.format_secondary_markup (_("An older version of clinica has been detected and the old database has to be moved\nto a new location to continue.\n<b>The older version of clinica won't work anymore with this setup</b>.\nDo you still want to continue?"));
+                    if (mb.run () != Gtk.ResponseType.YES) {
+                        mb.destroy ();
+                        Posix.exit (1);
+                    }
+                    
+                    mb.destroy ();
+                
+                    debug ("Moving old database to its new location (starting from clinica 0.2.9)");
+                    try {
+                        old_db_file.copy (db_file, FileCopyFlags.ALL_METADATA);
+                        FileUtils.remove (old_db_file.get_path ());
+                    } catch (GLib.Error e) {
+                        error (_("Error while transferring the database to the new default location for clinica >= 0.2.9"));
+                    }
+                }
+            }
+        }
+
+        /**
+         * @brief Do upgrade the database starting from db_version.
+         */
+        private bool upgrade_database (string db_version) {
+            /* Try to open the database first */
+            if (!(Database.open (database_path, out db) == OK)) {
+                error (_("Error upgrading database, please check your installation"));
+            }
+            
+            string sql;
+            Statement stmt;
+            int64 rc;
+            
+            /* Performing upgrade from 0.1 */
+            if (db_version == "0.1") {
+                /* We need to create the new table for the events */
+               sql = "CREATE TABLE IF NOT EXISTS events (id INTEGER PRIMARY KEY, title TEXT, description TEXT, venue TEXT, patient INTEGER, visit INTEGER, date TEXT);";
+               db.prepare (sql, -1, out stmt, null);
+               rc = stmt.step ();
+               
+               if (rc != DONE) {
+                   error (_("Error upgrading the database from version 0.1 to 0.2, sqlite exit code: %I64d".printf (rc)));
+                   return false;
+               } else {
+                   db_version = "0.2";
+               }
+            }
+            
+            return true;
+        }
+        
+        /**
+         * @brief Check that all the resources needed by Clinica
+         * are actually available, and if they are not create them.
+         */
+        public void init_resources () {
+            int64 rc;
+            Statement stmt;
+            string sql;
+            
+            /* Open database and, if it does not exists, create it */
+            if (!(Database.open (database_path, out db) == OK)) {
+                error ("Error opening database.");
+            };
+            
+            /* Check if the required tables exists */
+            sql = "SELECT * from sqlite_master WHERE type='table';";
+            db.prepare (sql, -1, out stmt, null);
+            rc = stmt.step ();
+            
+            if (rc == DONE) {
+                /* That means no tables in the database */
+                init_database ();
+            }
+        }
+        
+        
+        /**
+         * @brief Init the database with the required tables
+         */
+        private void init_database () {
+            
+            if (db.exec ("CREATE TABLE IF NOT EXISTS doctors (surname TEXT, ID INTEGER PRIMARY KEY, phone TEXT, mobile TEXT, given_name TEXT)") != 0)
+                error ("Error creating the doctors table");
+            if (db.exec ("CREATE TABLE IF NOT EXISTS patients (gender TEXT, doctor INTEGER, surname TEXT, ID INTEGER PRIMARY KEY, identification_code TEXT, phone TEXT, given_name TEXT, birth_date TEXT, residence_address TEXT)") != 0)
+                error ("Error creating the patients table");
+            if (db.exec ("CREATE TABLE IF NOT EXISTS visits (subsequent_checks TEXT, systemic_therapy TEXT, ID INTEGER PRIMARY KEY, laboratory_exam TEXT, diagnosis TEXT, histopathology TEXT, anamnesis TEXT, date TEXT, patient INTEGER, physical_examination TEXT, topical_therapy TEXT)") != 0)
+                error ("Error creating the visits table");
+            if (db.exec ("CREATE TABLE IF NOT EXISTS events (id INTEGER PRIMARY KEY, title TEXT, description TEXT, venue TEXT, patient INTEGER, visit INTEGER, date TEXT)") != 0)
+                error ("Error creating the events table");
+                
+        }
+            
+        /**
+         * @brief Internal routine used to convert DateTime objects
+         * to strings that are to be saved in the database.
+         */
+        private static string datetime_to_string (DateTime date) {
+            return string.join(" ", 
+        		date.get_year ().to_string (), 
+        		"%.2d".printf (date.get_month ()), 
+        		"%.2d".printf (date.get_day_of_month()), 
+        		"%.2d".printf (date.get_hour ()), 
+        		"%.2d".printf (date.get_minute ()), 
+        		"%.2d".printf (date.get_second ()));
+        }
+        
+       /**
+        * @brief Convert strings encoded with datetime_to_string () back
+        * to DateTime objects.
+        */
+       private static DateTime string_to_datetime (string input) {
+        	string [] fields = input.split(" ");
+        	
+        	int year = int.parse (fields[0]);
+        	int month = int.parse (fields[1]);
+        	int day = int.parse (fields[2]);
+        	int hour = int.parse (fields[3]);
+        	int minute = int.parse (fields[4]);
+        	int seconds = int.parse (fields[5]);
+        	
+        	if (year < 1 || year > 9999 || 
+        		month < 1 || month > 12 ||
+        		day < 1 || day > 31 ||
+        		minute < 0 || minute > 59 ||
+        		seconds < 0 || seconds > 59)
+        		return new DateTime.now_local ();
+        	
+        	return new DateTime.local (year, month, day, hour, minute, seconds);
+        }
+        
+        /* IMPLEMENTATION OF THE ABSTRACT INTERFACES OF DataProvider */
+        
+        public Doctor get_doctor (int64 id) {
+            var doc = new Doctor ();
+            Statement stmt;
+            db.prepare (@"SELECT given_name, surname, phone, mobile FROM $(doctor_table) WHERE id=$(id);", -1, 
+                out stmt, null);
+            if (!(stmt.step () == ROW)) {
+                error (_("Error while retrieving the doctor with id = %I64d").printf (id, db.errmsg ()));
+            }
+            
+            /* Load data from the database into the fields */
+            doc.id = id;
+            doc.given_name = stmt.column_text (0).compress ();
+            doc.surname = stmt.column_text (1).compress ();
+            doc.phone = stmt.column_text (2).compress ();
+            doc.mobile = stmt.column_text (3).compress ();
+            
+            doc.provider = this;
+            
+            return doc;
+        }
+        
+        public int64 save_doctor (Doctor doctor) {
+            Statement stmt;
+            
+            if (doctor.id != 0)
+                db.prepare ("""INSERT OR REPLACE INTO %s (id, given_name, surname, phone, mobile)
+                    VALUES (:id, :given_name, :surname, :phone, :mobile);""".printf (doctor_table),
+                    -1, out stmt);
+            else
+                db.prepare ("""INSERT OR REPLACE INTO %s (given_name, surname, phone, mobile)
+                    VALUES (:given_name, :surname, :phone, :mobile);""".printf (doctor_table),
+                    -1, out stmt);
+            
+                
+            
+            /* Bind values present in doctor in the SQL statement */
+            int i = 1;
+            if (doctor.id != 0)
+                stmt.bind_int64  (i++, doctor.id);
+            stmt.bind_text (i++, doctor.given_name);
+            stmt.bind_text (i++, doctor.surname);
+            stmt.bind_text (i++, doctor.phone);
+            stmt.bind_text (i++, doctor.mobile);
+            
+            if (stmt.step () != DONE) {
+                error (_("An error occurred while saving the doctor with id %d: %s").printf (doctor.id, db.errmsg ()));
+                return -1;
+            }
+            
+            if (doctor.id == 0) {
+                doctor.id = db.last_insert_rowid ();
+                doctor_added (doctor.id);
+            }
+            else
+                doctor_changed (doctor.id);
+
+            return doctor.id;
+        }
+        
+        public int64 remove_doctor (Doctor doctor) {
+            Statement stmt;
+            
+        	/* Keep a list of the patient ID we need to notify */
+        	var patients = new List<int64?> ();
+        	foreach (var patient in doctor.patients ()) {
+        	    patients.append (patient.id);
+        	}
+            
+            /* Wrap all this in a transaction so the DB doesn't change until
+             * we commit */
+            db.exec ("BEGIN TRANSACTION");
+            
+        	string sql = @"DELETE from $(doctor_table) WHERE ID=$(doctor.id);";
+        	
+        	db.prepare (sql, -1, out stmt, null);
+        	if (stmt.step () != DONE) {
+        		error (@"Error deleting doctor with id $(doctor.id)");
+        		db.exec ("ROLLBACK TRANSACTION");
+        		return -1;
+        	}
+        	
+        	/* Now we need to deassociate its patients from him/her */
+            if (db.exec (@"UPDATE $(patient_table) SET doctor = 0 WHERE doctor = $(doctor.id);") != 0) {
+                error (@"Error deassociating the patients from the doctor with ID = $(doctor.id)");
+                db.exec ("ROLLBACK TRANSACTION");
+                return -1;
+            }
+            
+        	db.exec ("COMMIT TRANSACTION");
+        	
+        	doctor_removed (doctor.id);
+        	
+        	/* Notify changes on the patients */
+        	foreach (var patient_id in patients) {
+        	    patient_changed (patient_id);
+        	}
+        	return 0;
+        }
+        
+        public PatientIterator patients (Doctor? doctor = null) {
+            return new SqlitePatientIterator (this, (doctor == null) ? "" : @"WHERE doctor = $(doctor.id)");
+        }
+        
+        public DoctorIterator doctors () {
+            return new SqliteDoctorIterator (this);
+        }
+        
+        public Patient get_patient (int64 id) {
+            var patient = new Patient ();
+            Statement stmt;
+            db.prepare ("""SELECT given_name, surname, birth_date, gender, phone, residence_address,
+                    identification_code, doctor FROM %s WHERE id=%I64d;""".printf (patient_table, id), 
+                    -1, out stmt, null);
+            if (!(stmt.step () == ROW)) {
+                error (_("Error while retrieving the patient with id = %I64d").printf (id, db.errmsg ()));
+            }
+            
+            /* Load data from the database into the fields */
+            patient.id = id;
+            patient.given_name = stmt.column_text (0).compress ();
+            patient.surname = stmt.column_text (1).compress ();
+            patient.birth_date = string_to_datetime (stmt.column_text (2).compress ());
+            patient.gender = (stmt.column_text (3) == "MALE") ? Gender.MALE : Gender.FEMALE;
+            patient.phone = stmt.column_text (4).compress ();
+            patient.residence_address = stmt.column_text (5).compress ();
+            patient.identification_code = stmt.column_text (6).compress ();
+            patient.doctor = (stmt.column_int64 (7) == 0) ? null : get_doctor (stmt.column_int64 (7));
+            
+            patient.provider = this;
+            
+            return patient;
+        }
+        
+        public int64 save_patient (Patient patient) {
+            Statement stmt;
+            
+            if (patient.id != 0)
+                db.prepare ("""INSERT OR REPLACE INTO %s
+                    (ID, given_name, surname, birth_date, gender, phone, residence_address, identification_code, doctor)
+                    VALUES (:id, :given_name, :surname, :birth_date, :gender, :phone, :residence_address, :identification_code, :doctor);""".printf (patient_table),
+                    -1, out stmt);
+            else
+                db.prepare ("""INSERT OR REPLACE INTO %s
+                            (given_name, surname, birth_date, gender, phone, residence_address, identification_code, doctor)
+                            VALUES (:given_name, :surname, :birth_date, :gender, :phone, :residence_address, :identification_code, :doctor);""".printf (patient_table),
+                    -1, out stmt);
+            
+            
+            /* Bind values present in doctor in the SQL statement */
+            int i = 1;
+            if (patient.id != 0)
+                stmt.bind_int64  (i++, patient.id);
+            stmt.bind_text   (i++, patient.given_name);
+            stmt.bind_text   (i++, patient.surname);
+            stmt.bind_text   (i++, datetime_to_string (patient.birth_date));
+            stmt.bind_text   (i++, (patient.gender == Gender.MALE) ? "MALE" : "FEMALE");
+            stmt.bind_text   (i++, patient.phone);
+            stmt.bind_text   (i++, patient.residence_address);
+            stmt.bind_text   (i++, patient.identification_code);
+            stmt.bind_int64  (i++, (patient.doctor == null) ? 0 : patient.doctor.id);
+            
+            if (stmt.step () != DONE) {
+                error (_("An error occurred while saving the doctor with id %I64d: %s").printf (patient.id, db.errmsg ()));
+                return -1;
+            }
+            
+            if (patient.id == 0) {
+                patient.id = db.last_insert_rowid ();
+                patient_added (patient.id);
+            }
+            else
+                patient_changed (patient.id);
+                
+            return patient.id;
+        }
+        
+        public int64 remove_patient (Patient patient) {
+        	
+        	db.exec ("BEGIN TRANSACTION");
+        	
+        	if (db.exec (@"DELETE from $(patient_table) WHERE ID=$(patient.id)") != 0) {
+        		error (@"Error deleting patient with id $(patient.id)");
+        		db.exec ("ROLLBACK TRANSACTION");
+        		return -1;
+        	}
+        	
+        	/* Try to remove all the visits of the patient */
+        	if (db.exec (@"DELETE FROM $(visit_table) WHERE patient=$(patient.id)") != 0) {
+        	    error (@"Error deleting the visits associated to the patient");
+        	    db.exec ("ROLLBACK TRANSACTION");
+        	    return -1;
+        	}
+        	
+        	/* Deassoociate all the events associated with this patient */
+        	if (db.exec (@"UPDATE $(event_table) SET patient=0 WHERE patient=$(patient.id)") != 0) {
+        	    error (@"Error deassociating the events from the deleted patient");
+        	    db.exec ("ROLLBACK TRANSACTION");
+        	    return -1;
+            }
+            
+            db.exec ("COMMIT TRANSACTION");
+        	
+        	patient_removed (patient.id);
+        	return 0;
+        }
+        
+        public VisitIterator visits (Patient? patient, DateTime? start = null, DateTime? end = null) {
+            string sql_clause = (patient == null && start == null && end == null) ? "" : "WHERE";
+            
+            if (patient != null) {
+                sql_clause += @" patient = $(patient.id)";
+                if (start != null || end != null)
+                    sql_clause += " AND ";
+            }
+             
+            if (start == null && end == null)
+                return new SqliteVisitIterator (this, sql_clause);    
+            else if (start != null && end == null)
+                return new SqliteVisitIterator (this, sql_clause + @" date >= '$(datetime_to_string (start))'");
+            else if (start == null && end != null)
+                return new SqliteVisitIterator (this, sql_clause + @" date < '$(datetime_to_string (end))'");
+            else
+                return new SqliteVisitIterator (this, sql_clause + @" date BETWEEN " +
+                                                      @"'$(datetime_to_string (start))' AND '$(datetime_to_string (end))'");
+        }
+        
+        public Visit get_visit (int64 id) {
+            var visit = new Visit ();
+            Statement stmt;
+            db.prepare ("""SELECT anamnesis, physical_examination, laboratory_exam, histopathology, diagnosis,
+                        topical_therapy, systemic_therapy, subsequent_checks, date, patient
+                        FROM %s WHERE id=%I64d;""".printf (visit_table, id), -1,
+                        out stmt, null);
+            if (!(stmt.step () == ROW)) {
+                error (_("Error while retrieving the visit with id = %I64d").printf (id, db.errmsg ()));
+            }
+            
+            /* Load data from the database into the fields */
+            visit.id = id;
+            visit.anamnesis = stmt.column_text (0).compress ();
+            visit.physical_examination = stmt.column_text (1).compress ();
+            visit.laboratory_exam = stmt.column_text (2).compress ();
+            visit.histopathology = stmt.column_text (3).compress ();
+            visit.diagnosis = stmt.column_text (4).compress ();
+            visit.topical_therapy = stmt.column_text (5).compress ();
+            visit.systemic_therapy = stmt.column_text (6).compress ();
+            visit.subsequent_checks = stmt.column_text (7).compress ();
+            visit.date = string_to_datetime (stmt.column_text (8).compress ());
+            visit.patient = get_patient (stmt.column_int64 (9));
+            
+            visit.provider = this;
+            
+            return visit;
+        }
+        
+        public int64 save_visit (Visit visit) {
+            Statement stmt;
+            if (visit.id != 0)
+                db.prepare ("""INSERT OR REPLACE INTO %s 
+                    (id, anamnesis, physical_examination, laboratory_exam, histopathology, diagnosis,
+                    topical_therapy, systemic_therapy, subsequent_checks, date, patient)
+                    VALUES (:id, :anamnesis, :physical_examination, :laboratory_exam, :histopathology, :diagnosis,
+                    :topical_therapy, :systemic_therapy, :subsequent_checks, :date, :patient);""".printf (visit_table),
+                    -1, out stmt);
+            else
+                db.prepare ("""INSERT OR REPLACE INTO %s 
+                    (anamnesis, physical_examination, laboratory_exam, histopathology, diagnosis,
+                    topical_therapy, systemic_therapy, subsequent_checks, date, patient)
+                    VALUES (:anamnesis, :physical_examination, :laboratory_exam, :histopathology, :diagnosis,
+                    :topical_therapy, :systemic_therapy, :subsequent_checks, :date, :patient);""".printf (visit_table),
+                    -1, out stmt);            
+            
+            /* Bind values present in doctor in the SQL statement */
+            int i = 1;
+            if (visit.id != 0)
+                stmt.bind_int64  (i++, visit.id);
+            stmt.bind_text (i++, visit.anamnesis);
+            stmt.bind_text (i++, visit.physical_examination);
+            stmt.bind_text (i++, visit.laboratory_exam);
+            stmt.bind_text (i++, visit.histopathology);
+            stmt.bind_text (i++, visit.diagnosis);
+            stmt.bind_text (i++, visit.topical_therapy);
+            stmt.bind_text (i++, visit.systemic_therapy);
+            stmt.bind_text (i++, visit.subsequent_checks);
+            stmt.bind_text (i++, datetime_to_string (visit.date));
+            stmt.bind_int64  (i++, visit.patient.id);
+            
+            if (stmt.step () != DONE) {
+                error (_("An error occurred while saving the doctor with id %I64d: %s").printf (visit.id, db.errmsg ()));
+                return -1;
+            }
+            
+            if (visit.id == 0) {
+                visit.id = db.last_insert_rowid ();
+                visit_added (visit.id);
+            }
+            else
+                visit_changed (visit.id);
+            
+            return visit.id;
+        }
+        
+        public int64 remove_visit (Visit visit) {
+            Statement stmt;
+        	string sql = @"DELETE from $(visit_table) WHERE ID=$(visit.id);";
+        	
+        	db.prepare (sql, -1, out stmt, null);
+        	if (stmt.step () != DONE) {
+        		error (@"Error deleting visit with id $(visit.id)");
+        		return -1;
+        	}
+        	
+        	visit_removed (visit.id);
+        	return 0;
+        }
+        
+        public Event get_event (int64 id) {
+            var event = new Event ();
+            Statement stmt;
+            db.prepare (@"SELECT title, description, venue, patient, visit, date FROM $(event_table) WHERE id=$(id);", -1, 
+                        out stmt, null);
+            if (!(stmt.step () == ROW)) {
+                error (_("Error while retrieving the event with id = %d").printf (id, db.errmsg ()));
+            }
+            
+            /* Load data from the database into the fields */
+            event.id = id;
+            event.title = stmt.column_text (0).compress ();
+            event.description = stmt.column_text (1).compress ();
+            event.venue = stmt.column_text (2).compress ();
+            event.patient = (stmt.column_int64 (3) != 0) ? get_patient (stmt.column_int64 (3)) : null;
+            event.visit = (stmt.column_int64 (4) != 0) ? get_visit (stmt.column_int64 (4)) : null;
+            event.date = string_to_datetime (stmt.column_text (5).compress ());
+            
+            event.provider = this;
+            
+            return event;
+        }
+        
+        public int64 save_event (Event event) {
+            Statement stmt;
+            
+            if (event.id != 0)
+                db.prepare ("""INSERT OR REPLACE INTO %s (id, title, description, venue, patient, visit, date)
+                    VALUES (:id, :title, :description, :venue, :patient, :visit, :date);""".printf (event_table),
+                    -1, out stmt);
+            else
+                db.prepare ("""INSERT OR REPLACE INTO %s (title, description, venue, patient, visit, date)
+                    VALUES (:title, :description, :venue, :patient, :visit, :date);""".printf (event_table),
+                    -1, out stmt);            
+            
+            /* Bind values present in doctor in the SQL statement */
+            int i = 1;
+            if (event.id != 0)
+                stmt.bind_int64  (i++, event.id);
+            stmt.bind_text (i++, event.title);
+            stmt.bind_text (i++, event.description);
+            stmt.bind_text (i++, event.venue);
+            stmt.bind_int64  (i++, (event.patient == null) ? 0 : event.patient.id);
+            stmt.bind_int64  (i++, (event.visit == null) ? 0 : event.visit.id);
+            stmt.bind_text (i++, datetime_to_string (event.date));
+            
+            if (stmt.step () != DONE) {
+                error (_("An error occurred while saving the event with id %I64d: %s").printf (event.id, db.errmsg ()));
+                return -1;
+            }
+            
+            if (event.id == 0) {
+                event.id = db.last_insert_rowid ();
+                event_added (event.id);
+            }
+            else
+                event_changed (event.id);
+            
+            return event.id;
+        }
+        
+                
+        public int64 remove_event (Event event) {
+            Statement stmt;
+        	string sql = @"DELETE from $(event_table) WHERE ID=$(event.id);";
+        	
+        	db.prepare (sql, -1, out stmt, null);
+        	if (stmt.step () != DONE) {
+        		error (@"Error deleting event with id $(event.id)");
+        		return -1;
+        	}
+        	
+        	event_removed (event.id);
+        	return 0;
+        }
+        
+        public EventIterator events (DateTime? start = null, DateTime? end = null) {
+            string sql_clause = "";
+        
+            if (start == null && end == null)
+                return new SqliteEventIterator (this, sql_clause);
+            else if (start != null && end == null)
+                return new SqliteEventIterator (this, sql_clause + @" WHERE date >= '$(datetime_to_string (start))'");
+            else if (start == null && end != null)
+                return new SqliteEventIterator (this, sql_clause + @" WHERE date < '$(datetime_to_string (end))'");
+            else
+                return new SqliteEventIterator (this, sql_clause + @" WHERE date BETWEEN " +
+                                                      @"'$(datetime_to_string (start))' AND '$(datetime_to_string (end))'");
+        }
+    
+    }
+
+}

=== added file 'libclinica/SqliteDoctorIterator.vala'
--- libclinica/SqliteDoctorIterator.vala	1970-01-01 00:00:00 +0000
+++ libclinica/SqliteDoctorIterator.vala	2012-02-23 21:39:18 +0000
@@ -0,0 +1,45 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+
+using Sqlite;
+
+namespace Clinica {
+   
+    public class SqliteDoctorIterator : Object, DoctorIterator {
+
+		private SqliteDataProvider provider;
+		private Statement stmt;
+
+        public SqliteDoctorIterator (SqliteDataProvider provider, string clause = "") {
+            this.provider = provider;
+            provider.db.prepare ("SELECT id from %s %s;".printf (provider.doctor_table, clause), 
+                                 -1, out stmt);
+        }
+        
+        public bool next () {
+            return (stmt.step () == ROW);
+        }
+        
+        public new Doctor get () {
+            int id = stmt.column_int (0);
+            return provider.get_doctor (id); 
+        }
+    }
+
+}

=== added file 'libclinica/SqlitePatientIterator.vala'
--- libclinica/SqlitePatientIterator.vala	1970-01-01 00:00:00 +0000
+++ libclinica/SqlitePatientIterator.vala	2012-02-23 21:39:18 +0000
@@ -0,0 +1,45 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+
+using Sqlite;
+
+namespace Clinica {
+   
+    public class SqlitePatientIterator : Object, PatientIterator {
+        
+		private SqliteDataProvider provider;
+		private Statement stmt;
+
+        public SqlitePatientIterator (SqliteDataProvider provider, string clause = "") {
+            this.provider = provider;
+            provider.db.prepare ("SELECT id from %s %s;".printf (provider.patient_table, clause), 
+                                 -1, out stmt);
+        }
+        
+        public bool next () {
+            return (stmt.step () == ROW);
+        }
+        
+        public new Patient get () {
+            int id = stmt.column_int (0);
+            return provider.get_patient (id); 
+        }
+    }
+    
+}

=== added file 'libclinica/SqliteVisitIterator.vala'
--- libclinica/SqliteVisitIterator.vala	1970-01-01 00:00:00 +0000
+++ libclinica/SqliteVisitIterator.vala	2012-02-23 21:39:18 +0000
@@ -0,0 +1,44 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+
+using Sqlite;
+
+namespace Clinica {
+   
+    public class SqliteVisitIterator : GLib.Object, VisitIterator {
+        
+		private SqliteDataProvider provider;
+		private Statement stmt;
+
+        public SqliteVisitIterator (SqliteDataProvider provider, string clause = "") {
+            this.provider = provider;
+            provider.db.prepare ("SELECT id from %s %s ORDER by date DESC;".printf (provider.visit_table, clause), 
+                                 -1, out stmt);
+        }
+        
+        public bool next () {
+            return (stmt.step () == ROW);
+        }
+        
+        public new Visit get () {
+            int id = stmt.column_int (0);
+            return provider.get_visit (id); 
+        }
+    }
+}

=== modified file 'libclinica/UserInterface.vala'
--- libclinica/UserInterface.vala	2012-01-31 09:44:59 +0000
+++ libclinica/UserInterface.vala	2012-02-23 21:39:18 +0000
@@ -45,7 +45,7 @@
 		/* Windows */
 		internal SettingsManager? settings_manager = null;
 		internal CalendarWindow?  calendar_window  = null;
-		internal GLib.HashTable<int, VisitWindow> visit_windows;
+		internal GLib.HashTable<int64?, VisitWindow> visit_windows;
 		
 		private extern Peas.ExtensionSet setup_extension_set (ResourceManager resources, Peas.Engine engine);
 		internal Peas.ExtensionSet extension_set;
@@ -78,7 +78,7 @@
 	        }
 	        
 	        /* Create an empty HashTable to store the Visit windows */
-	        visit_windows = new HashTable<int, VisitWindow> (null, null);
+	        visit_windows = new HashTable<int64?, VisitWindow> (null, null);
 	        
 	        /* Load pages and connect callbacks with errors */
             start_page = new StartPage (resource_manager);
@@ -181,7 +181,7 @@
 		 * is already open than bring it on top.
 		 */
 		public VisitWindow show_visit_window (Patient p) {
-		    int p_id = p.get_id ();
+		    int64 p_id = p.id;
 
             VisitWindow? win = visit_windows.lookup (p_id);
             if (win == null) {

=== modified file 'libclinica/UserInterfaceActivatable.vala'
--- libclinica/UserInterfaceActivatable.vala	2011-09-22 19:27:52 +0000
+++ libclinica/UserInterfaceActivatable.vala	2012-02-23 21:39:18 +0000
@@ -1,3 +1,22 @@
+/*
+ *   This file is part of Clinica.
+ *
+ *   Clinica is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   Clinica is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *   Authors: Leonardo Robol <leo@xxxxxxxx>
+ */
+
 namespace Clinica {
 
     /**

=== modified file 'libclinica/Visit.vala'
--- libclinica/Visit.vala	2012-02-02 07:26:45 +0000
+++ libclinica/Visit.vala	2012-02-23 21:39:18 +0000
@@ -15,187 +15,36 @@
  *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
  *
  *   Authors: Leonardo Robol <leo@xxxxxxxx>
- *            Gianmarco Brocchi <brocchi@xxxxxxxxxxxxxxxxxxxx>
  */
  
- using Gee;
- using Sqlite;
- 
- namespace Clinica {
- 
-    public class VisitIterator : SqlDataIterator {
-    
-        
-		private ResourceManager resource_manager;
-
-        public VisitIterator (ResourceManager resources) {
-            base (resources.db, resources.visits_table, "date", true);
-            resource_manager = resources;
-        }
-        
-        public VisitIterator.with_day (ResourceManager resources, DateTime day, bool descending = true) {
-            DateTime day_after = day.add_days (1).add_minutes (-1);
-            base.with_like (resources.db, resources.visits_table, "date", descending, 
-                "date BETWEEN '%s' AND '%s'".printf (SqlDataType.datetime_to_string (day),
-                                                     SqlDataType.datetime_to_string (day_after)));
-            resource_manager = resources;
-        }
-        
-        public VisitIterator.with_patient (ResourceManager resources, Patient p, bool descending = true, 
-            DateTime? from = null, DateTime? to = null) {
-            
-            string base_like;
-            if (from == null && to == null) {
-                base_like = "patient = %d".printf (p.get_id ());
-            }
-            else if (from != null && to == null) {
-                base_like = "patient = %d AND date >= '%s'".printf (p.get_id (), SqlDataType.datetime_to_string (from));
-            }
-            else if (from == null && to != null) {
-                base_like  = "patient = %d AND date < '%s'".printf (p.get_id (), SqlDataType.datetime_to_string (to));
-            }
-            else {
-                 base_like = "patient = %d AND date BETWEEN '%s' AND '%s'".printf (p.get_id (), 
-                                SqlDataType.datetime_to_string (from),
-                                SqlDataType.datetime_to_string (to));
-            }
-              
-            base.with_like (resources.db, resources.visits_table, "date", descending, base_like);
-            resource_manager = resources;
-        }
-        
-        public new VisitIterator iterator () { return this; }
-        
-        public new Visit get () { 
-            return new Visit.with_id (resource_manager, base.get ()); 
-        }
-    }
- 
-    public class Visit : SqlDataType {
-        
-        /* FIELDS */
-        public string anamnesis {
-        	get { return get_text ("anamnesis"); }
-        	set { set_text ("anamnesis", value); }
-        }
-        
-        public string physical_examination {
-        	get { return get_text ("physical_examination"); }
-        	set { set_text ("physical_examination", value); }
-        }
-        
-        public string laboratory_exam {
-        	get { return get_text ("laboratory_exam"); }
-        	set { set_text ("laboratory_exam", value); }
-        }
-        
-        public string histopathology {
-        	get { return get_text ("histopathology"); }
-        	set { set_text ("histopathology", value); }
-        }
-        
-        public string diagnosis {
-        	get { return get_text ("diagnosis"); }
-        	set { set_text ("diagnosis", value); }
-        }
-        
-        public string topical_therapy {
-        	get { return get_text ("topical_therapy"); }
-        	set { set_text ("topical_therapy", value); }
-        }
-        
-        public string systemic_therapy {
-        	get { return get_text ("systemic_therapy"); }
-        	set { set_text ("systemic_therapy", value); }
-        }
-        
-        public string subsequent_checks {
-        	get { return get_text ("subsequent_checks"); }
-        	set { set_text ("subsequent_checks", value); }
-        }
-        
-        private DateTime _date;
-        public DateTime date {
-        	get { 
-        		_date = get_date ("date");
-        		return _date;
-        	}
-        	set {
-        		_date = value;
-        		set_date ("date", _date);
-        	}
-        }
-        
-        private Patient _patient;
-        public  Patient patient {
-        	get {
-        		_patient = new Patient.with_id (resource_manager, get_integer ("patient"));
-        		return _patient;
-        	}
-        	set {
-        		this._patient = value;
-        		set_integer("patient", value.get_id ());
-        	}
-        }
-        
-		private ResourceManager resource_manager;
-        
-        /**
-         * @brief Create a new visit to 
-         * the passed patient.
-         * @param patient The patient that has been
-         * visited
-         */
-        public Visit (ResourceManager resources, Patient? patient) {
-            base (resources.db);
-            resource_manager = resources;
-            table_name = resources.visits_table;
-            error.connect ((t,l) => resources.error_callback(t,l));
-            table_name = "visits";
-            
-            add_text_field ("anamnesis");
-            add_text_field ("physical_examination");
-            add_text_field ("laboratory_exam");
-            add_text_field ("histopathology");
-            add_text_field ("diagnosis");
-            add_text_field ("topical_therapy");
-            add_text_field ("systemic_therapy");
-            add_text_field ("subsequent_checks");
-            add_date_field ("date");
-            
-            add_integer_field ("patient");
-            
-            if (patient != null) {
-                this.patient = patient;
-            }
-            
-            anamnesis = "";
-            physical_examination = "";
-            laboratory_exam = "";
-            histopathology = "";
-            diagnosis = "";
-            topical_therapy = "";
-            systemic_therapy = "";
-            subsequent_checks = "";
-
-            init_resources ();
-        }
-        
-        public Visit.with_id (ResourceManager resources, int ID) {
-            this (resources, null);
-            load (ID);
-            this.patient = new Patient.with_id (resources, get_integer ("patient"));
-        }
-        
-        public static new VisitIterator all (ResourceManager resources) {
-            return new VisitIterator (resources);
-        }
-        
-        public static new VisitIterator for_day (ResourceManager resources, DateTime date, bool descending = false) {
-            return new VisitIterator.with_day (resources, date, descending);
-        }
-       
-    }
- 
- 
- }
+namespace Clinica {
+
+    public class Visit : Object {
+   
+        public DataProvider? provider = null;
+        
+        public int64 id { get; set; default = 0; }
+    
+        public string anamnesis { get; set; default = ""; }
+            
+        public string physical_examination { get; set; default = ""; }
+            
+        public string laboratory_exam { get; set; default = ""; }
+            
+        public string histopathology { get; set; default = ""; }
+            
+        public string diagnosis { get; set; default = ""; }
+            
+        public string topical_therapy { get; set; default = ""; }
+            
+        public string systemic_therapy { get; set; default = ""; }
+            
+        public string subsequent_checks { get; set; default = ""; }
+            
+        public DateTime date { get; set; }
+            
+        public Patient patient { get; set; default = null; }
+    
+    }
+
+}

=== modified file 'libclinica/VisitActions.vala'
--- libclinica/VisitActions.vala	2011-11-23 17:53:36 +0000
+++ libclinica/VisitActions.vala	2012-02-23 21:39:18 +0000
@@ -95,7 +95,7 @@
              * visit. */
             this.visit_tab = visittab;
             visit_connection_id = visit_tab.saved.connect ((visit) => delete_button.set_sensitive (true));
-            if (visit_tab.visit.get_id () != 0)
+            if (visit_tab.visit.id != 0)
                 delete_button.set_sensitive (true);
             else
                 delete_button.set_sensitive (false);

=== modified file 'libclinica/VisitBrowser.vala'
--- libclinica/VisitBrowser.vala	2012-02-02 08:11:46 +0000
+++ libclinica/VisitBrowser.vala	2012-02-23 21:39:18 +0000
@@ -15,7 +15,6 @@
  *   along with Clinica.  If not, see <http://www.gnu.org/licenses/>.
  *
  *   Authors: Leonardo Robol <leo@xxxxxxxx>
- *            Gianmarco Brocchi <brocchi@xxxxxxxxxxxxxxxxxxxx>
  */
 
 using Gtk;
@@ -63,7 +62,7 @@
 			Label l;
 			
 			/* Put in future visits */
-			foreach (Visit v in new VisitIterator.with_patient (resource_manager, p, true, new DateTime.now_local ())) {
+			foreach (Visit v in p.visits (new DateTime.now_local ())) {
 				l = new Label(v.date.format ("%F"));
 				append_page (new VisitTab (resource_manager, visit_window, v, l), l);
 				old_pages++;
@@ -78,12 +77,12 @@
 			new_tab_saved_connection_id = new_page.saved.connect (on_new_page_saved);
 				
 			/* And then load all visits for the patient */
-			foreach (Visit v in new VisitIterator.with_patient (resource_manager, p, true, null, new DateTime.now_local ())) {
+			foreach (Visit v in p.visits (null, new DateTime.now_local ())) {
 				l = new Label(v.date.format ("%F"));
 				append_page (new VisitTab (resource_manager, visit_window, v, l), l);
 			}
 			
-			store.visit_added.connect (on_visit_list_store_visit_added);
+			resource_manager.data_provider.visit_added.connect (on_visit_added);
 		}
 		
 		public void save_focused_visit () {
@@ -102,9 +101,9 @@
 		 * @brief This callback gets called when a visit is added, probably
 		 * in another VisitBrowser. 
 		 */
-		private void on_visit_list_store_visit_added (int visit_id) {
+		private void on_visit_added (int64 visit_id) {
 		    /* Get the new visit */
-		    Visit new_visit = new Visit.with_id (resource_manager, visit_id);       
+		    Visit new_visit = resource_manager.data_provider.get_visit (visit_id);
             		
 		    /* We may be the VisitBrowser that added the visit, or not.
 		     * Let's find out traversing the tabs */
@@ -113,7 +112,7 @@
 		    
 		    for (i = 0; i < n_pages; i++) {
 		        VisitTab tab = get_nth_page (i) as VisitTab;
-		        int visit_tab_id = tab.visit.get_id ();
+		        int64 visit_tab_id = tab.visit.id;
 		        
 		        if (visit_tab_id == visit_id) {
 		            return;
@@ -147,7 +146,7 @@
 			
 			/* Check if the visit is already in db. If it is, save it, otherwise
 			 * ask the user to do it, since it may not be what he desires */
-			if (tab.visit.get_id () <= 0) {
+			if (tab.visit.id <= 0) {
 			    Gtk.MessageDialog dialog = new MessageDialog.with_markup (null,
 			        DialogFlags.MODAL, MessageType.QUESTION, ButtonsType.YES_NO,
 			        _("A visit need to be saved in order to be exported as PDF.\nDo you want to save the visit now?"));

=== modified file 'libclinica/VisitDetail.vala'
--- libclinica/VisitDetail.vala	2012-02-02 08:38:15 +0000
+++ libclinica/VisitDetail.vala	2012-02-23 21:39:18 +0000
@@ -124,8 +124,7 @@
 		                                    MessageType.QUESTION, ButtonsType.YES_NO, "%s", 
 		                                    _("Deleting a visit will cause all its data to be lost.\nDo you really want to continue?"));
 		    if (dialog.run () == ResponseType.YES) {
-                associated_visit.remove ();
-                resource_manager.visit_list_store.remove_visit (associated_visit);
+		        resource_manager.data_provider.remove_visit (associated_visit);
             }
             
             dialog.destroy ();

=== modified file 'libclinica/VisitFileManager.vala'
--- libclinica/VisitFileManager.vala	2012-01-29 15:44:14 +0000
+++ libclinica/VisitFileManager.vala	2012-02-23 21:39:18 +0000
@@ -96,7 +96,7 @@
                     Gtk.Stock.SAVE, Gtk.ResponseType.ACCEPT);
             fd.set_transient_for (visit_window);
             if (fd.run () == Gtk.ResponseType.ACCEPT) {
-                resource_manager.file_store.store_file (visit.get_id (), fd.get_filename ());
+                resource_manager.file_store.store_file (visit.id, fd.get_filename ());
             }
             
             fd.destroy ();
@@ -108,7 +108,7 @@
          */
         private void on_browse_button_clicked (Button button) {
             try {
-                string path = resource_manager.file_store.get_id_path (visit.get_id ());
+                string path = resource_manager.file_store.get_id_path (visit.id);
                 Gtk.show_uri (null, "file://" + path, Gdk.CURRENT_TIME);
             } catch (GLib.Error e) {
                 warning (_("Unable to open the browser on the filestore position"));
@@ -120,8 +120,8 @@
          * reload the files if the file changed were the ones that 
          * belong to this visit.
          */
-        private void on_file_store_changed (int id) {
-            if (visit != null && id == visit.get_id ())
+        private void on_file_store_changed (int64 id) {
+            if (visit != null && id == visit.id)
                 reload_file_list ();
         }
         
@@ -148,7 +148,7 @@
                 (attach_button.get_child () as Label).set_text (_("Attach files"));
             }
 
-            foreach (FileObject obj in resource_manager.file_store.get_files (visit.get_id ())) {
+            foreach (FileObject obj in resource_manager.file_store.get_files (visit.id)) {
                 var file_detail = new FileDetail (resource_manager, visit_window, obj);
                 pack_start (file_detail, false, true);
                 file_detail.show_all ();

=== modified file 'libclinica/VisitListStore.vala'
--- libclinica/VisitListStore.vala	2012-01-26 17:41:05 +0000
+++ libclinica/VisitListStore.vala	2012-02-23 21:39:18 +0000
@@ -24,9 +24,6 @@
 
 	public class VisitListStore : ListStore {
 	
-	    public signal void visit_added   (int visit_id);
-	    public signal void visit_removed (int visit_id);
-	
 		enum Field {
 			VISIT,
 			DATE,
@@ -48,64 +45,49 @@
 			
 			/* Fill liststore asynchronously */
 			Idle.add(() => {
-				foreach (Visit v in Visit.all (resource_manager)) {
-					add_visit (v);
+				foreach (Visit v in resource_manager.data_provider.visits ()) {
+					add_visit (v.id);
 				}
 				
+    	        /* Setup callbacks to add or remove doctors */
+		        resource_manager.data_provider.visit_added.connect (
+		            (id) => add_visit (id));
+		        resource_manager.data_provider.visit_changed.connect (
+		            (id) => reload_visit (id));
+		        resource_manager.data_provider.visit_removed.connect (
+		            (id) => remove_visit (id));
+				
 				/* We don't need to execute any more */
 				return false;
 			});
 		}
 		
-		public void add_visit (Visit v) {
+		private void add_visit (int64 id) {
+		    Visit v = resource_manager.data_provider.get_visit (id);
 			TreeIter iter;
 			append (out iter);
 			set_value (iter, Field.VISIT, v);
 			set_value (iter, Field.DATE, "");
-			
-			visit_added (v.get_id ());
 		}
 		
-		public void reload_visit (Visit v) {
+		private void reload_visit (int64 id) {
+		    Visit v = resource_manager.data_provider.get_visit (id);
 			TreeIter iter = visit_to_iter (v);
 			set_value (iter, Field.VISIT, v);
 			set_value (iter, Field.DATE, "");
 		}
 		
-		/** @brief Get visits of the given patient */
-		public List<TreeIter?> get_visits_of (Patient p) {
-			Value value;
-			var iters = new List<TreeIter?> ();
-			
-			TreeIter it;
-			Visit v;
-			
-			if (!get_iter_first (out it)) {
-				return iters;
-			}
-			do {
-				get_value (it, Field.VISIT, out value);
-				v = value as Visit;
-				if (p.get_id () == v.patient.get_id ()) {
-					iters.append (it);
-				}
-			} while (iter_next (ref it));
-			return iters;
-		}
-		
-		public void remove_visit (Visit v) {
+		private void remove_visit (int64 id) {
 			TreeIter it;
 			Value visit;
-			int this_id = v.get_id ();
 			
 			if (!get_iter_first (out it)) {
 				error(_("Visit database seems corrupted. This is likely to be a bug in the application"));
 			}
 			do {
 				get_value (it, Field.VISIT, out visit);
-				if ((visit as Visit).get_id () == this_id) {
+				if ((visit as Visit).id == id) {
 					remove (it);
-				    visit_removed (this_id);
 					return;
 				}
 			} while (iter_next (ref it));
@@ -113,15 +95,6 @@
 			assert_not_reached ();
 		}
 		
-		public void remove_visit_from_iter (TreeIter it) {
-			Value visit;
-			get_value (it, Field.VISIT, out visit);
-			int this_id = (visit as Visit).get_id ();
-			(visit as Visit).remove ();
-			remove (it);
-			visit_removed (this_id);
-		}
-		
 		public Visit iter_to_visit (TreeIter it) {
 			Value visit;
 			get_value (it, Field.VISIT, out visit);
@@ -135,7 +108,7 @@
 				assert_not_reached ();
 			do {
 				get_value (iter, Field.VISIT, out visit);
-				if ((visit as Visit).get_id () == v.get_id ()) {
+				if ((visit as Visit).id == v.id) {
 					return iter;
 				}
 			} while (iter_next (ref iter));

=== modified file 'libclinica/VisitSchedulerDialog.vala'
--- libclinica/VisitSchedulerDialog.vala	2012-02-02 17:00:18 +0000
+++ libclinica/VisitSchedulerDialog.vala	2012-02-23 21:39:18 +0000
@@ -84,12 +84,12 @@
         
             if (base.run () == Response.SAVE) {
                 /* Saving the new visit in the database */                
-                Visit visit = new Visit (resource_manager, p_entry.get_patient ());
+                Visit visit = new Visit ();
+                visit.patient = p_entry.get_patient ();
                 visit.date = picker.get_datetime ();
                 
-                /* And finally save the visit in the database AND the ListStore */
-                visit.save ();
-                resource_manager.visit_list_store.add_visit (visit);
+                /* And finally save the visit in the database */
+                resource_manager.data_provider.save_visit (visit);
             }
             
             return Response.CANCEL;

=== modified file 'libclinica/VisitTab.vala'
--- libclinica/VisitTab.vala	2012-02-02 08:38:15 +0000
+++ libclinica/VisitTab.vala	2012-02-23 21:39:18 +0000
@@ -176,27 +176,28 @@
 				fill_data ();
 				
 		    /* Connect callbacks */
-		    store.visit_removed.connect (on_visit_list_store_visit_removed);
+		    resource_manager.data_provider.visit_removed.connect (on_visit_removed);
 		}
 		
 		public VisitTab.with_patient (ResourceManager resources, VisitWindow window, Patient p, Label title) {
 			this (resources, window, null, title);
-			visit = new Visit (resource_manager, p);
+			visit = new Visit ();
+			visit.patient = p;
 		}
 		
 		/**
 		 * @brief Get the visit id.
 		 */
-		public int get_visit_id () {
-		    return visit.get_id ();
+		public int64 get_visit_id () {
+		    return visit.id;
 		}
 		
 		/**
 		 * @brief Callback to the visit_removed event in the liststore.
 		 */
-		private void on_visit_list_store_visit_removed (int visit_id) {
+		private void on_visit_removed (int64 visit_id) {
 		    VisitBrowser parent = this.parent as VisitBrowser;
-		    if (visit_id == visit.get_id ())
+		    if (visit_id == visit.id)
 		        parent.remove_page (parent.page_num (this));
 		}
 		
@@ -241,12 +242,7 @@
 			/* ..and then actually store that data in the database, changing
 			 * the label of the tab to reflect the change...              */
 			label.set_text (visit.date.format ("%F"));
-			visit.save ();
-			
-			if (new_visit)
-				store.add_visit (visit);
-			else
-				store.reload_visit (visit);
+			resource_manager.data_provider.save_visit (visit);
 			
 		    file_manager.update_visit (visit);
 			
@@ -264,8 +260,7 @@
 		                                    MessageType.QUESTION, ButtonsType.YES_NO, "%s", 
 		                                    _("Deleting a visit will cause all its data to be lost.\nDo you really want to continue?"));
 		    if (dialog.run () == ResponseType.YES) {
-			    store.remove_visit (visit);
-			    visit.remove ();
+			    resource_manager.data_provider.remove_visit (visit);
 			
 			    /* Emit deleted() signal */
 			    deleted();

=== modified file 'libclinica/VisitWindow.vala'
--- libclinica/VisitWindow.vala	2012-01-27 07:27:43 +0000
+++ libclinica/VisitWindow.vala	2012-02-23 21:39:18 +0000
@@ -70,7 +70,7 @@
 		 * to deattach it from the user_interface visit_window hashtable.
 		 */
 		public void on_visit_window_destroy (Widget me) {
-		    resource_manager.user_interface.visit_windows.remove (patient.get_id ());
+		    resource_manager.user_interface.visit_windows.remove (patient.id);
 		    resource_manager.application.remove_window (this);
 		}
 		
@@ -81,7 +81,7 @@
 		    int i;
 		    for (i = 0; i < visit_browser.get_n_pages (); i++) {
 		        VisitTab nth_visit_tab = visit_browser.get_nth_page (i) as VisitTab;
-		        if (nth_visit_tab.get_visit_id () == visit.get_id ()) {
+		        if (nth_visit_tab.get_visit_id () == visit.id) {
 		            visit_browser.set_current_page (i);
 		            return;
 		        }

=== modified file 'org.phcteam.clinica.gschema.xml'
--- org.phcteam.clinica.gschema.xml	2012-01-29 10:39:56 +0000
+++ org.phcteam.clinica.gschema.xml	2012-02-23 21:39:18 +0000
@@ -16,9 +16,18 @@
       <summary>Selected medicine search engine</summary>
       <description>The name of the search engine that the user wants to lookup medicines.</description>
     </key>
+    <key name="data-provider" type="s">
+      <default>""</default>
+      <summary>Selected data provider</summary>
+      <description>The name of the data provider used to retrieve the data in Clinica.</description>
+    </key>
     <key name="show-visit-file-manager" type="b">
       <default>true</default>
       <summary>Show "Open file browser" button in the visit window</summary>
     </key>
+    <key name="password" type="s">
+      <default>"password"</default>
+      <summary>The password used to sync with the clinica instance via wireless</summary>
+    </key>
   </schema>
 </schemalist>

=== modified file 'plugins/AgenziaDelFarmaco.plugin'
--- plugins/AgenziaDelFarmaco.plugin	2011-09-21 16:46:53 +0000
+++ plugins/AgenziaDelFarmaco.plugin	2012-02-23 21:39:18 +0000
@@ -2,8 +2,8 @@
 Loader=python
 Module=AgenziaDelFarmaco
 IAge=3
-Name=Search for medicine on agenziadelfarmaco.it
-Description=Search for medical products on the italian "Agenzia del Farmaco"
+Name=Agenzia del Farmaco
+Description=Search for medical products on the italian database of agenziadelfarmaco.it
 Authors=Leonardo Robol
 Copyright=2011 Leonardo Robol
 Website=

=== added file 'plugins/ClinicaAndroid.plugin'
--- plugins/ClinicaAndroid.plugin	1970-01-01 00:00:00 +0000
+++ plugins/ClinicaAndroid.plugin	2012-02-23 21:39:18 +0000
@@ -0,0 +1,6 @@
+[Plugin]
+Module = ClinicaAndroid
+Loader = python
+Name = Clinica for Android
+Description = Server to sync Android phones with Clinica
+Author = Leonardo Robol

=== added file 'plugins/ClinicaAndroid.py'
--- plugins/ClinicaAndroid.py	1970-01-01 00:00:00 +0000
+++ plugins/ClinicaAndroid.py	2012-02-23 21:39:18 +0000
@@ -0,0 +1,130 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import SocketServer, md5, threading, os
+from gi.repository import Clinica, GObject, Gtk, PeasGtk, Gio
+from socket import gethostname
+
+authenticated_clients = []
+
+class ClinicaAndroid (GObject.GObject, Clinica.UserInterfaceActivatable, PeasGtk.Configurable):
+
+    resource_manager = GObject.property (type = Clinica.ResourceManager)
+    user_interface = GObject.property (type = Clinica.UserInterface)
+
+    __gtype_name__ = "ClinicaAndroid"
+
+    server = None
+
+    def __init__(self):
+        GObject.GObject.__init__(self)
+
+    def do_activate (self):
+        self.clinica_db = os.path.join (self.resource_manager.get_data_path (), 
+                                        "clinica.db")
+
+        self.server = ClinicaServer (self.clinica_db)
+        self.server_thread = threading.Thread (target = self.server.serve_forever)
+        self.server_thread.start ()
+
+        self.tcpserver = ClinicaTCPServer (self.clinica_db)
+        self.tcpserver_thread = threading.Thread (target = self.tcpserver.serve_forever)
+        self.tcpserver_thread.start ()
+
+    def do_deactivate (self):
+        self.server.shutdown ()
+        self.server_thread.join ()
+        self.tcpserver.shutdown ()
+        self.tcpserver_thread.join ()
+
+    def do_create_configure_widget (self):
+        settings = Gio.Settings.new ("org.phcteam.clinica")
+        box = Gtk.Box.new (Gtk.Orientation.HORIZONTAL, 6)
+        
+        label = Gtk.Label ("Password")
+        entry = Gtk.Entry ()
+
+        box.pack_start (label, 6, False, True)
+        box.pack_start (entry, 6, True,  True)
+
+        settings.bind ("password", entry, "text", Gio.SettingsBindFlags.DEFAULT)
+
+        return box
+
+    def on_name_entry_changed (self, entry):
+        self.server.set_name (entry.get_text ())
+        
+    def do_update_state (self):
+        pass
+        
+
+class ClinicaRequestHandler (SocketServer.BaseRequestHandler):
+    
+    def handle (self):
+        password = self.server.settings.get_value ("password").get_string ()
+        
+        data = self.request[0].strip ()
+        socket = self.request[1]
+
+        if data == "GetInfo":
+            socket.sendto ("ServerName: %s\n" % self.server.name, self.client_address)
+
+        elif data.startswith ("Authenticate:"):
+            pw = data.split(":")[1].strip ()
+            
+            if self.client_address[0] in authenticated_clients:
+                socket.sendto ("Authentication performed\n", self.client_address)
+            else:
+                if password == pw:
+                    authenticated_clients.append (self.client_address[0])
+                    socket.sendto ("Authentication performed\n", self.client_address)
+                else:
+                    socket.sendto ("Authentication failed\n", self.client_address)
+
+        elif data == "GetDB":
+            if self.client_address[0] in authenticated_clients:
+                try:
+                    with open (self.server.db_path) as h : db_content = h.read ()
+                    socket.sendto (db_content, self.client_address)
+                except Exception, e:
+                    socket.sendto ("Sending DB failed : %s" % e, self.client_address)
+            else:
+                socket.sendto ("Autenticati, scemo\n", self.client_address)
+
+class ClinicaTCPRequestHandler (SocketServer.BaseRequestHandler):
+
+    def handle (self):
+        data = self.request.recv(1024).strip()
+        if data == "GetDB":
+            if self.client_address[0] in authenticated_clients:
+                with open (self.server.db_path) as h : db_content = h.read ()
+                self.request.sendall (db_content)
+        
+
+class ClinicaTCPServer (SocketServer.ThreadingTCPServer):
+
+    allow_reuse_address = True
+
+    def __init__(self, db_path, port = 20802):
+        SocketServer.ThreadingTCPServer.__init__(self, ('', port), ClinicaTCPRequestHandler)
+        
+        self.db_path = db_path
+        self.name = gethostname()
+
+class ClinicaServer (SocketServer.ThreadingUDPServer):
+
+    allow_reuse_address = True
+
+    def __init__ (self, db_path, port = 20801):
+        SocketServer.ThreadingUDPServer.__init__ (self, ('', port), ClinicaRequestHandler)
+        self.db_path = db_path
+        self.name = gethostname()
+        self.settings = Gio.Settings.new ("org.phcteam.clinica")
+
+
+if __name__ == "__main__":
+
+    udp_server = ClinicaServer ("Ciao")
+    tcp_server = ClinicaTCPServer ("Ciao")
+
+    server.serve_forever ()

=== modified file 'plugins/wscript'
--- plugins/wscript	2012-01-24 09:36:22 +0000
+++ plugins/wscript	2012-02-23 21:39:18 +0000
@@ -1,8 +1,12 @@
 #!/usr/bin/env python
 #
 
+import os
+
 plugins_install_path = "${PREFIX}/lib/clinica/plugins"
 
+plugins = []
+
 def build (ctx):
     ctx.set_group ("clinica")
 
@@ -29,11 +33,21 @@
     ctx.install_files (plugins_install_path, [ "AgenziaDelFarmaco.py",
                                                "AgenziaDelFarmaco.plugin" ])
 
+    # Add plugins
+    add_plugin ("AgenziaDelFarmaco")
+    add_plugin ("DummyDataProvider")
+    # add_plugin ("GPGEncryption")
+    add_plugin ("CodiceFiscale")
+    add_plugin ("ClinicaAndroid")
+
     # Push plugins on the build directory so we can run
     # clinica in the local dir
-    for plugin in [ 'AgenziaDelFarmaco.plugin', 'CodiceFiscale.plugin', 'AgenziaDelFarmaco.py',
-                    ]:
+    for plugin in plugins:
         push_plugin (ctx, plugin)
+
+def add_plugin (plugin_name):	
+    plugins_files = filter (lambda x : x.startswith (plugin_name), os.listdir ("plugins"))
+    plugins.extend (plugins_files)
     
     
 def push_plugin (ctx, plugin_file):    

=== modified file 'po/es.po'
--- po/es.po	2012-02-08 08:06:57 +0000
+++ po/es.po	2012-02-23 21:39:18 +0000
@@ -11,12 +11,18 @@
 "PO-Revision-Date: 2012-02-07 13:41+0000\n"
 "Last-Translator: Fitoschido <fitoschido@xxxxxxxxx>\n"
 "Language-Team: Spanish <es@xxxxxx>\n"
+"Language: es\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
+<<<<<<< TREE
 "X-Launchpad-Export-Date: 2012-02-08 08:06+0000\n"
 "X-Generator: Launchpad (build 14747)\n"
 "Language: es\n"
+=======
+"X-Launchpad-Export-Date: 2012-01-31 07:02+0000\n"
+"X-Generator: Launchpad (build 14734)\n"
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/Doctor.vala:110
 msgid ""
@@ -259,8 +265,13 @@
 msgstr "Visitas realizadas"
 
 #: ../libclinica/CalendarEventList.vala:102
+#, fuzzy
 msgid "Visits scheduled"
+<<<<<<< TREE
 msgstr "Visitas agendadas"
+=======
+msgstr "Eventos agendados"
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/CalendarEventList.vala:123
 msgid "No visits performed on this day"
@@ -329,8 +340,8 @@
 
 #: ../libclinica/DoctorListView.vala:186
 msgid ""
-"The doctor that you have selected for removal has some patients associated. "
-"\n"
+"The doctor that you have selected for removal has some patients "
+"associated. \n"
 msgstr ""
 "El doctor que ha elegido para ser eliminado tiene algunos pacientes "
 "asignados. \n"
@@ -360,8 +371,7 @@
 msgstr "Confirmar la eliminación de pacientes"
 
 #: ../libclinica/DoctorListView.vala:244
-msgid ""
-"Really delete this doctor? All information about him/her will be lost."
+msgid "Really delete this doctor? All information about him/her will be lost."
 msgstr ""
 "¿Seguro de eliminar este médico? Toda la información del médico será perdida."
 
@@ -713,25 +723,24 @@
 msgid "Mobile:"
 msgstr "Móvil:"
 
+#~ msgid "Error loading patient_editor.glade."
+#~ msgstr "Error al cargar patient_editor.glade"
+
+#~ msgid ""
+#~ "\n"
+#~ "Launchpad contributions: \n"
+#~ msgstr ""
+#~ "\n"
+#~ "Contribuciones de Launchpad: \n"
+
 #~ msgid "Create a new patient"
 #~ msgstr "Crear un nuevo paciente"
 
 #~ msgid "Create a new doctor"
 #~ msgstr "Crear un nuevo médico"
 
-#, c-format
 #~ msgid "Clinica %s\n"
 #~ msgstr "Clínica %s\n"
 
 #~ msgid "Back"
 #~ msgstr "Atrás"
-
-#~ msgid "Error loading patient_editor.glade."
-#~ msgstr "Error al cargar patient_editor.glade"
-
-#~ msgid ""
-#~ "\n"
-#~ "Launchpad contributions: \n"
-#~ msgstr ""
-#~ "\n"
-#~ "Contribuciones de Launchpad: \n"

=== modified file 'po/it.po'
--- po/it.po	2012-02-14 06:40:10 +0000
+++ po/it.po	2012-02-23 21:39:18 +0000
@@ -10,12 +10,18 @@
 "PO-Revision-Date: 2012-02-13 15:15+0000\n"
 "Last-Translator: Gianmarco Brocchi <Unknown>\n"
 "Language-Team: Clinica Development team\n"
+"Language: \n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
+<<<<<<< TREE
 "X-Launchpad-Export-Date: 2012-02-14 06:40+0000\n"
 "X-Generator: Launchpad (build 14781)\n"
 "Language: \n"
+=======
+"X-Launchpad-Export-Date: 2012-01-31 07:02+0000\n"
+"X-Generator: Launchpad (build 14734)\n"
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/Doctor.vala:110
 msgid ""
@@ -117,8 +123,7 @@
 
 #: ../libclinica/PatientEditor.vala:436
 msgid "Date inserted is invalid, aborting patient editing"
-msgstr ""
-"La data inserita non è valida: non è possibile modificare il paziente"
+msgstr "La data inserita non è valida: non è possibile modificare il paziente"
 
 #. Set title according to the patient that we have loaded and connect
 #. * show startup signal to the focusing of the first field in the visit
@@ -257,8 +262,13 @@
 msgstr "Visite effettuate"
 
 #: ../libclinica/CalendarEventList.vala:102
+#, fuzzy
 msgid "Visits scheduled"
+<<<<<<< TREE
 msgstr "Visita programmata"
+=======
+msgstr "Eventi in programma"
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/CalendarEventList.vala:123
 msgid "No visits performed on this day"
@@ -327,8 +337,8 @@
 
 #: ../libclinica/DoctorListView.vala:186
 msgid ""
-"The doctor that you have selected for removal has some patients associated. "
-"\n"
+"The doctor that you have selected for removal has some patients "
+"associated. \n"
 msgstr ""
 "Il dottore che è stato selezionato per la rimozione è associato a dei "
 "pazienti. \n"
@@ -360,8 +370,7 @@
 msgstr "Conferma la rimozione dei pazienti"
 
 #: ../libclinica/DoctorListView.vala:244
-msgid ""
-"Really delete this doctor? All information about him/her will be lost."
+msgid "Really delete this doctor? All information about him/her will be lost."
 msgstr ""
 "Si è sicuri di voler rimuovere il medico? Tutte le informazioni su di lui o "
 "lei saranno perse."
@@ -714,12 +723,6 @@
 msgid "Mobile:"
 msgstr "Telefono cellulare:"
 
-#~ msgid "Create a new patient"
-#~ msgstr "Crea un nuovo paziente"
-
-#~ msgid "Create a new doctor"
-#~ msgstr "Crea un nuovo medico"
-
 #~ msgid "Error loading patient_editor.glade."
 #~ msgstr "Errore durante il caricamento di patient_editor.glade."
 
@@ -730,7 +733,12 @@
 #~ "\n"
 #~ "Contributi su Launchpad: \n"
 
-#, c-format
+#~ msgid "Create a new patient"
+#~ msgstr "Crea un nuovo paziente"
+
+#~ msgid "Create a new doctor"
+#~ msgstr "Crea un nuovo medico"
+
 #~ msgid "Clinica %s\n"
 #~ msgstr "Clinica %s\n"
 

=== modified file 'po/pt_BR.po'
--- po/pt_BR.po	2012-02-06 05:08:51 +0000
+++ po/pt_BR.po	2012-02-23 21:39:18 +0000
@@ -7,43 +7,52 @@
 msgstr ""
 "Project-Id-Version: clinica-project\n"
 "Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
+<<<<<<< TREE
 "POT-Creation-Date: 2012-02-02 18:49+0100\n"
 "PO-Revision-Date: 2012-02-05 15:24+0000\n"
 "Last-Translator: Marco <marcodefreitas@xxxxxxxxx>\n"
+=======
+"POT-Creation-Date: 2012-01-29 11:43+0100\n"
+"PO-Revision-Date: 2012-02-02 05:16+0000\n"
+"Last-Translator: Marco <marcodefreitas@xxxxxxxxx>\n"
+>>>>>>> MERGE-SOURCE
 "Language-Team: Brazilian Portuguese <pt_BR@xxxxxx>\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
+<<<<<<< TREE
 "X-Launchpad-Export-Date: 2012-02-06 05:08+0000\n"
 "X-Generator: Launchpad (build 14747)\n"
+=======
+"X-Launchpad-Export-Date: 2012-02-02 06:29+0000\n"
+"X-Generator: Launchpad (build 14738)\n"
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/Doctor.vala:110
 msgid ""
 "You cannot delete a doctor with associated patients. Delete his patients "
 "first."
 msgstr ""
+<<<<<<< TREE
 "Você não pode excluir um médico com pacientes associados. Exclua seus "
 "pacientes em primeiro lugar."
+=======
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/VisitListStore.vala:102
 msgid ""
 "Visit database seems corrupted. This is likely to be a bug in the application"
 msgstr ""
-"O banco de dados de visita parece corrompido. É provável que isto seja um "
-"bug no aplicativo."
 
-#: ../libclinica/UserInterface.vala:281
+#: ../libclinica/UserInterface.vala:282
 #, c-format
 msgid "Cannot open the help: %s"
-msgstr "Não é possível abrir a ajuda: %s"
-
-#: ../libclinica/UserInterface.vala:301
-msgid ""
-"An error occurred while opening the bug system. Please go to\n"
-"http://launchpad.net/clinica-project/ to file a bug"
 msgstr ""
+<<<<<<< TREE
 "Ocorreu um erro ao abrir o sistema de bugs. Por favor, visite\n"
 "http://launchpad.net/clinica-project/ para reportar o bug"
+=======
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/PatientListPage.vala:74
 msgid "Patients"
@@ -51,27 +60,30 @@
 
 #: ../libclinica/PatientListView.vala:76
 #: ../libclinica/MedicineTreeView.vala:18 ../libclinica/DoctorListView.vala:51
-#: ../ui/patient_editor.glade.h:2 ../ui/doctor_editor.glade.h:2
+#: ../ui/patient_editor.glade.h:5 ../ui/doctor_editor.glade.h:3
 msgid "Name"
-msgstr "Nome:"
+msgstr "Nome"
 
 #. ...and then the surname column
 #: ../libclinica/PatientListView.vala:80 ../libclinica/DoctorListView.vala:56
-#: ../ui/patient_editor.glade.h:3 ../ui/doctor_editor.glade.h:3
+#: ../ui/patient_editor.glade.h:6 ../ui/doctor_editor.glade.h:4
 msgid "Surname"
 msgstr "Sobrenome"
 
 #: ../libclinica/PatientListView.vala:174
 msgid "Select a patient to delete it!"
-msgstr "Selecione um paciente para apagá-lo!"
+msgstr ""
 
 #: ../libclinica/PatientListView.vala:181
 msgid ""
 "Really delete this patient? All information about him/her and the associated "
 "visits will be lost."
 msgstr ""
+<<<<<<< TREE
 "Deseja realmente excluir este paciente? Todas as informações sobre ela/ela e "
 "as consultas associadas serão perdidas."
+=======
+>>>>>>> MERGE-SOURCE
 
 #. Print the error message to stdout
 #: ../libclinica/Utils.vala:79
@@ -99,17 +111,21 @@
 msgid "Price"
 msgstr "Preço"
 
+#: ../libclinica/PatientEditor.vala:102
+msgid "Error loading patient_editor.glade."
+msgstr "Erro ao carregar patient_editor.glade."
+
 #. Set title to edit patient * instead of create new patient
-#: ../libclinica/PatientEditor.vala:297
+#: ../libclinica/PatientEditor.vala:307
 #, c-format
 msgid "Edit patient named %s"
 msgstr "Editar o paciente chamado %s"
 
-#: ../libclinica/PatientEditor.vala:401
+#: ../libclinica/PatientEditor.vala:411
 msgid "You must select a doctor for this patient."
 msgstr "É preciso selecionar um médico para este paciente."
 
-#: ../libclinica/PatientEditor.vala:402
+#: ../libclinica/PatientEditor.vala:412
 msgid ""
 "If you need to create a new one type his name in the entry and select Create "
 "new doctor from the completion list."
@@ -117,9 +133,9 @@
 "Se você precisa criar um tipo novo digite o seu nome na entrada e selecione "
 "Criar novo médico a partir da lista de conclusão."
 
-#: ../libclinica/PatientEditor.vala:436
+#: ../libclinica/PatientEditor.vala:446
 msgid "Date inserted is invalid, aborting patient editing"
-msgstr "A data inserida é inválida, abortando a edição de paciente"
+msgstr ""
 
 #. Set title according to the patient that we have loaded and connect
 #. * show startup signal to the focusing of the first field in the visit
@@ -134,8 +150,11 @@
 "Patients database seems corrupted. This is likely to be a bug in the "
 "application"
 msgstr ""
+<<<<<<< TREE
 "O banco de dados de pacientes parece corrompido. É provável que seja um bug "
 "no aplicativo"
+=======
+>>>>>>> MERGE-SOURCE
 
 #. Create menu items, connect them to their callback
 #. * and add it to the menu
@@ -175,11 +194,11 @@
 
 #: ../libclinica/MedicineDetailDialog.vala:54
 msgid "Active ingredient"
-msgstr "Princípio ativo"
+msgstr ""
 
 #: ../libclinica/MedicineDetailDialog.vala:55
 msgid "Storage reccomendations"
-msgstr "Recomendações de armazenamento"
+msgstr ""
 
 #: ../libclinica/MedicineDetailDialog.vala:64
 msgid "Additional notes"
@@ -190,24 +209,27 @@
 msgid "Field empty"
 msgstr "Campo vazio"
 
-#. Then add add a new visit and keep a reference to new_page
+#. First add a new visit and keep a reference to new_page
 #. *  to focus it on page loading.
 #. Create a new one and connect it
-#: ../libclinica/VisitBrowser.vala:74 ../libclinica/VisitBrowser.vala:196
+#: ../libclinica/VisitBrowser.vala:62 ../libclinica/VisitBrowser.vala:184
 msgid "New visit"
 msgstr "Nova consulta"
 
-#: ../libclinica/VisitBrowser.vala:153
+#: ../libclinica/VisitBrowser.vala:141
 msgid ""
 "A visit need to be saved in order to be exported as PDF.\n"
 "Do you want to save the visit now?"
 msgstr ""
+<<<<<<< TREE
 "A consulta precisa ser salva para que possa ser exportada como PDF.\n"
 "Deseja salvar a consulta agora?"
+=======
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/SettingsManager.vala:44
 msgid "Clinica settings"
-msgstr "Configurações do Clinica"
+msgstr ""
 
 #. Create the use-plugins checkbox
 #: ../libclinica/SettingsManager.vala:56
@@ -216,11 +238,11 @@
 
 #: ../libclinica/SettingsManager.vala:63
 msgid "Allow to browse files in visits"
-msgstr "Permitir procurar arquivos em consultas"
+msgstr ""
 
 #: ../libclinica/SettingsManager.vala:76
 msgid "General"
-msgstr "Geral"
+msgstr ""
 
 #: ../libclinica/SettingsManager.vala:80
 msgid "Plugins"
@@ -231,17 +253,20 @@
 "Select the search engine\n"
 "used to find medicines"
 msgstr ""
+<<<<<<< TREE
 "Selecione o sistema de pesquisa\n"
 "utilizado para encontrar medicamentos."
+=======
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/DoctorListStore.vala:73
 msgid "Doctors database seems corrupted."
-msgstr "O banco de dados de médicos parece corrompido."
+msgstr ""
 
 #. Start of events
 #: ../libclinica/CalendarEventList.vala:70
 msgid "Events scheduled"
-msgstr "Eventos agendados"
+msgstr ""
 
 #: ../libclinica/CalendarEventList.vala:89
 msgid ""
@@ -249,25 +274,18 @@
 "You can create a new event\n"
 "by clicking on the top-left button."
 msgstr ""
-"Sem eventos para hoje.\n"
-"Você pode criar um novo evento\n"
-"clicando no botão superior esquerdo"
 
-#: ../libclinica/CalendarEventList.vala:100
+#: ../libclinica/CalendarEventList.vala:95
 msgid "Visits performed"
-msgstr "Consultas realizadas"
-
-#: ../libclinica/CalendarEventList.vala:102
-msgid "Visits scheduled"
-msgstr "Consultas agendadas"
-
-#: ../libclinica/CalendarEventList.vala:123
+msgstr ""
+
+#: ../libclinica/CalendarEventList.vala:115
 msgid "No visits performed on this day"
-msgstr "Sem consultas realizadas hoje"
+msgstr ""
 
 #: ../libclinica/VisitToolbar.vala:90
 msgid "This patient has not a doctor"
-msgstr "Este paciente não tem um médico"
+msgstr ""
 
 #: ../libclinica/VisitToolbar.vala:93
 #, c-format
@@ -275,13 +293,11 @@
 "Patient: <b>%s</b>\n"
 "Doctor: <b>%s</b>"
 msgstr ""
-"Paciente: <b>%s</b>\n"
-"Médico: <b>%s</b>"
 
 #. Show more details on this patient
 #: ../libclinica/VisitActions.vala:61
 msgid "Edit patient details"
-msgstr "Editar detalhes do paciente"
+msgstr ""
 
 #. Save the visit as a PDF file
 #: ../libclinica/VisitActions.vala:71
@@ -290,29 +306,29 @@
 
 #: ../libclinica/EventEditor.vala:93
 msgid "Create a new event"
-msgstr "Criar novo evento"
+msgstr ""
 
 #: ../libclinica/EventEditor.vala:97
 #, c-format
 msgid "Editing event: %s"
-msgstr "Editando evento: %s"
+msgstr ""
 
 #. Create the entry for title of the event and venue
 #: ../libclinica/EventEditor.vala:114
 msgid "Title"
-msgstr "Tí­tulo"
+msgstr ""
 
 #: ../libclinica/EventEditor.vala:115
 msgid "Venue"
-msgstr "Local"
+msgstr ""
 
 #: ../libclinica/EventEditor.vala:144
 msgid "Time:"
-msgstr "Hora:"
+msgstr ""
 
 #: ../libclinica/EventEditor.vala:160
 msgid "Insert the description here..."
-msgstr "Insira a descrição aqui…"
+msgstr ""
 
 #: ../libclinica/EventEditor.vala:198
 msgid "Patient"
@@ -320,48 +336,54 @@
 
 #: ../libclinica/EventEditor.vala:255
 msgid "Visit"
-msgstr "Consulta"
+msgstr ""
 
 #: ../libclinica/DoctorListView.vala:175
 msgid "Select a doctor to delete it!"
+<<<<<<< TREE
 msgstr "Selecione um médico para excluí-lo!"
+=======
+msgstr ""
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/DoctorListView.vala:186
 msgid ""
 "The doctor that you have selected for removal has some patients associated. "
 "\n"
 msgstr ""
-"O médico que você selecionou para remoção possui alguns pacientes "
-"associados. \n"
 
 #: ../libclinica/DoctorListView.vala:187
 msgid ""
 "It's not possible to remove it without removing all his patients.\n"
 "\n"
 msgstr ""
+<<<<<<< TREE
 "Não é possível removê-lo sem remover todos os seus pacientes.\n"
 "\n"
+=======
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/DoctorListView.vala:188 ../libclinica/DoctorListView.vala:221
 msgid "Do you really want to proceed?"
-msgstr "Você realmente deseja continuar?"
+msgstr ""
 
 #: ../libclinica/DoctorListView.vala:189
 msgid "Doctor has associated patients"
-msgstr "Este médico tem pacientes associados"
+msgstr ""
 
 #: ../libclinica/DoctorListView.vala:219
 msgid "The following patients will be deleted by this action:\n"
-msgstr "Os seguintes pacientes serão eliminados por esta ação:\n"
+msgstr ""
 
 #: ../libclinica/DoctorListView.vala:222
 msgid "Confirm deletion of patients"
-msgstr "Confirme a exclusão dos pacientes"
+msgstr ""
 
 #: ../libclinica/DoctorListView.vala:244
 msgid ""
 "Really delete this doctor? All information about him/her will be lost."
 msgstr ""
+<<<<<<< TREE
 "Você deseja realmente excluir este médico? Todas as informações sobre "
 "ele/ela serão perdidas."
 
@@ -372,104 +394,131 @@
 msgstr ""
 "Apagar uma consulta fará com que todos os seus dados sejam perdidos.\n"
 "Você realmente deseja continuar?"
+=======
+>>>>>>> MERGE-SOURCE
 
 #. Anamnesis
-#: ../libclinica/VisitTab.vala:283 ../libclinica/VisitPrinter.vala:68
+#: ../libclinica/VisitTab.vala:272 ../libclinica/VisitPrinter.vala:68
 msgid "Anamnesis"
 msgstr "Anamnese"
 
 #. Physical examination
-#: ../libclinica/VisitTab.vala:286 ../libclinica/VisitPrinter.vala:71
+#: ../libclinica/VisitTab.vala:275 ../libclinica/VisitPrinter.vala:71
 msgid "Physical examination"
 msgstr "Exame físico"
 
 #. Laboratory Exam
-#: ../libclinica/VisitTab.vala:289 ../libclinica/VisitPrinter.vala:74
+#: ../libclinica/VisitTab.vala:278 ../libclinica/VisitPrinter.vala:74
 msgid "Laboratory exam"
-msgstr "Exame laboratorial"
+msgstr ""
 
-#: ../libclinica/VisitTab.vala:292
+#: ../libclinica/VisitTab.vala:281
 msgid "Hystopathology"
-msgstr "Histopatologia"
+msgstr ""
 
 #. Diagnosis
-#: ../libclinica/VisitTab.vala:295 ../libclinica/VisitPrinter.vala:80
+#: ../libclinica/VisitTab.vala:284 ../libclinica/VisitPrinter.vala:80
 msgid "Diagnosis"
-msgstr "Diagnóstico"
+msgstr ""
 
 #. Topical therapy
-#: ../libclinica/VisitTab.vala:298 ../libclinica/VisitPrinter.vala:83
+#: ../libclinica/VisitTab.vala:287 ../libclinica/VisitPrinter.vala:83
 msgid "Topical therapy"
+<<<<<<< TREE
 msgstr "Terapia tópica"
+=======
+msgstr ""
+>>>>>>> MERGE-SOURCE
 
 #. Systemic therapy
-#: ../libclinica/VisitTab.vala:301 ../libclinica/VisitPrinter.vala:86
+#: ../libclinica/VisitTab.vala:290 ../libclinica/VisitPrinter.vala:86
 msgid "Systemic therapy"
-msgstr "Terapia sistêmica"
+msgstr ""
 
 #. Subsequent checks
-#: ../libclinica/VisitTab.vala:304 ../libclinica/VisitPrinter.vala:89
+#: ../libclinica/VisitTab.vala:293 ../libclinica/VisitPrinter.vala:89
 msgid "Subsequent checks"
+<<<<<<< TREE
 msgstr "Verificações subseqüentes"
+=======
+msgstr ""
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/PluginManager.vala:35
 msgid ""
 "Clinica is extensible via plugins and you can easily enable\n"
 " and disable them using this window."
 msgstr ""
+<<<<<<< TREE
 "O Clinica é extensível através de plugins e você pode facilmente ativá-los\n"
 " e desativá-los usando esta janela."
+=======
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/CalendarWindow.vala:36
 msgid "Clinica calendar"
+<<<<<<< TREE
 msgstr "Calendário do Clínica"
+=======
+msgstr ""
+>>>>>>> MERGE-SOURCE
 
 #. Histopathology
 #: ../libclinica/VisitPrinter.vala:77
 msgid "Histopathology"
-msgstr "Histopatologia"
+msgstr ""
 
 #: ../libclinica/EventListStore.vala:93
 msgid ""
 "Events database seems corrupted. This is likely to be a bug in the "
 "application"
 msgstr ""
-"O banco de dados de eventos parece corrompido. Isto pode ser um bug do "
-"aplicativo"
 
 #. Set title of edit doctor dialog, space is important!
-#: ../libclinica/DoctorEditor.vala:88
+#: ../libclinica/DoctorEditor.vala:91
 #, c-format
 msgid "Edit doctor named %s"
-msgstr "Edite o nome do médico %s"
-
-#: ../libclinica/ResourceManager.vala:221
+msgstr ""
+
+#: ../libclinica/ResourceManager.vala:215
+msgid ""
+"Error while transferring the database to the new default location for "
+"clinica >= 0.2.9"
+msgstr ""
+
+#: ../libclinica/ResourceManager.vala:236
 #, c-format
 msgid "Error creating some configuration files, check permission on %s"
 msgstr ""
+<<<<<<< TREE
 "Erro na criação de alguns arquivos de configuração, verifique as permissões "
 "em %s"
+=======
+>>>>>>> MERGE-SOURCE
 
-#: ../libclinica/ResourceManager.vala:229
+#: ../libclinica/ResourceManager.vala:244
 #, c-format
 msgid "Error reading some configuration files, check permission on %s"
 msgstr ""
-"Erro ao ler alguns arquivos de configuração, verifique as permissões em %s"
 
-#: ../libclinica/ResourceManager.vala:248
+#: ../libclinica/ResourceManager.vala:263
 #, c-format
 msgid "Failure while settings new database version to %s"
+<<<<<<< TREE
 msgstr "Falha ao alterar a nova versão do banco de dados para %s"
+=======
+msgstr ""
+>>>>>>> MERGE-SOURCE
 
-#: ../libclinica/ResourceManager.vala:251
+#: ../libclinica/ResourceManager.vala:266
 msgid "Failure while upgrading database"
-msgstr "A atualização do banco de dados falhou"
+msgstr ""
 
-#: ../libclinica/ResourceManager.vala:255
+#: ../libclinica/ResourceManager.vala:270
 msgid "Version of the database is not compatible"
-msgstr "A versão do banco de dados não é compatível"
+msgstr ""
 
-#: ../libclinica/ResourceManager.vala:330
+#: ../libclinica/ResourceManager.vala:345
 msgid ""
 "This is a version of Clinica newer than the one that created the\n"
 "patients database installed on the system.\n"
@@ -483,10 +532,11 @@
 "<b>a versão antiga não será capaz de usá-lo mais</ b>.\n"
 "Você deseja realizar a atualização de uma só vez?\n"
 
-#: ../libclinica/ResourceManager.vala:331
+#: ../libclinica/ResourceManager.vala:346
 msgid "Upgrade database"
 msgstr "Atualizar banco de dados"
 
+<<<<<<< TREE
 #: ../libclinica/ResourceManager.vala:356
 msgid "Database needs to be moved"
 msgstr "O banco de dados precisa ser movido"
@@ -515,17 +565,23 @@
 "0.2.9"
 
 #: ../libclinica/ResourceManager.vala:453
+=======
+#: ../libclinica/ResourceManager.vala:434
+>>>>>>> MERGE-SOURCE
 msgid "Error upgrading database, please check your installation"
 msgstr ""
 "Erro ao atualizar o banco de dados, por favor verifique sua instalação"
 
-#: ../libclinica/ResourceManager.vala:468
+#: ../libclinica/ResourceManager.vala:449
 #, c-format
 msgid ""
 "Error upgrading the database from version 0.1 to 0.2, sqlite exit code: %d"
 msgstr ""
+<<<<<<< TREE
 "Ocorreu um erro ao atualizar o banco de dados da versão 0.1 para 0.2, código "
 "de saída do sqlite: %d"
+=======
+>>>>>>> MERGE-SOURCE
 
 #: ../libclinica/AboutDialog.vala:40
 msgid "Medical records manager"
@@ -543,26 +599,34 @@
 msgid "Gianmarco Brocchi <brocchi@xxxxxxxxxxxxxxxxxxxx>\n"
 msgstr "Gianmarco Brocchi <brocchi@xxxxxxxxxxxxxxxxxxxx>\n"
 
+#. Start of LAUNCHPAD contributions. Each one is indented
+#. * of two spaces
+#: ../libclinica/AboutDialog.vala:56
+msgid ""
+"\n"
+"Launchpad contributions: \n"
+msgstr ""
+
 #: ../libclinica/DoctorListPage.vala:70
 msgid "Doctors"
-msgstr "Médicos"
+msgstr ""
 
 #: ../libclinica/MedicineSearchPage.vala:54
 msgid "Stop"
-msgstr "Parar"
+msgstr ""
 
 #: ../libclinica/MedicineSearchPage.vala:108
 msgid "No search engine available"
-msgstr "Não há mecanismos de pesquisas disponíveis"
+msgstr ""
 
 #: ../libclinica/MedicineSearchPage.vala:116
 #, c-format
 msgid "Searching for %s..."
-msgstr "Procurando por %s..."
+msgstr ""
 
 #: ../libclinica/MedicineSearchPage.vala:143
 msgid "Medicine search"
-msgstr "Pesquisa médica"
+msgstr ""
 
 #: ../libclinica/MedicineSearchPage.vala:104
 msgid "It's not possible to perform a search for medicine"
@@ -570,11 +634,11 @@
 
 #: ../ui/new_button.glade.h:1
 msgid "Browse the patients to start a visit"
-msgstr "Explorar pacientes para agendar uma consulta"
+msgstr ""
 
 #: ../ui/new_button.glade.h:2
 msgid "Add new patient"
-msgstr "Adicionar novo paciente"
+msgstr ""
 
 #: ../ui/new_button.glade.h:3
 msgid "Patient list"
@@ -582,7 +646,7 @@
 
 #: ../ui/new_button.glade.h:4
 msgid "Doctor list"
-msgstr "Lista de médicos"
+msgstr ""
 
 #: ../ui/new_button.glade.h:5
 msgid "Search medicines"
@@ -602,19 +666,19 @@
 
 #: ../ui/window.glade.h:3
 msgid "New Patient"
-msgstr "Novo Paciente"
+msgstr ""
 
 #: ../ui/window.glade.h:4
 msgid "New Doctor"
-msgstr "Novo Médico"
+msgstr ""
 
 #: ../ui/window.glade.h:5
 msgid "_Quit"
-msgstr "_Sair"
+msgstr ""
 
 #: ../ui/window.glade.h:6
 msgid "_View"
-msgstr "_Visualizar"
+msgstr ""
 
 #: ../ui/window.glade.h:7
 msgid "_Home"
@@ -638,78 +702,83 @@
 
 #: ../ui/window.glade.h:12
 msgid "_Settings"
-msgstr "_Configurações"
+msgstr ""
 
 #: ../ui/window.glade.h:13
 msgid "_Help"
-msgstr "A_juda"
+msgstr ""
 
 #: ../ui/window.glade.h:14
 msgid "_Contents"
+<<<<<<< TREE
 msgstr "_Conteúdo"
+=======
+msgstr ""
+>>>>>>> MERGE-SOURCE
 
 #: ../ui/window.glade.h:15
-msgid "_Report a bug"
-msgstr "_Reporte um problema"
-
-#: ../ui/window.glade.h:16
 msgid "_About"
-msgstr "_Sobre"
+msgstr ""
 
 #: ../ui/patient_editor.glade.h:1
+msgid "Male"
+msgstr ""
+
+#: ../ui/patient_editor.glade.h:2
+msgid "Female"
+msgstr ""
+
+#: ../ui/patient_editor.glade.h:3
+msgid "Create a new patient"
+msgstr ""
+
+#: ../ui/patient_editor.glade.h:4
 msgid "Patient:"
 msgstr "Paciente:"
 
-#: ../ui/patient_editor.glade.h:4
+#: ../ui/patient_editor.glade.h:7
 msgid "Gender:"
 msgstr "Sexo:"
 
-#: ../ui/patient_editor.glade.h:5
+#: ../ui/patient_editor.glade.h:8
 msgid "Date of birth:"
 msgstr "Data de nascimento:"
 
-#: ../ui/patient_editor.glade.h:6
+#: ../ui/patient_editor.glade.h:9
 msgid "dd"
 msgstr "dd"
 
-#: ../ui/patient_editor.glade.h:7
+#: ../ui/patient_editor.glade.h:10
 msgid "/"
 msgstr "/"
 
-#: ../ui/patient_editor.glade.h:8
+#: ../ui/patient_editor.glade.h:11
 msgid "mm"
 msgstr "mm"
 
-#: ../ui/patient_editor.glade.h:9
+#: ../ui/patient_editor.glade.h:12
 msgid "yyyy"
 msgstr "aaaa"
 
-#: ../ui/patient_editor.glade.h:10
+#: ../ui/patient_editor.glade.h:13
 msgid "Address:"
 msgstr "Endereço:"
 
-#: ../ui/patient_editor.glade.h:11 ../ui/doctor_editor.glade.h:4
+#: ../ui/patient_editor.glade.h:14 ../ui/doctor_editor.glade.h:5
 msgid "Phone:"
 msgstr "Telefone:"
 
-#: ../ui/patient_editor.glade.h:12 ../ui/doctor_editor.glade.h:1
+#: ../ui/patient_editor.glade.h:15 ../ui/doctor_editor.glade.h:2
 msgid "Doctor:"
-msgstr "Médico:"
+msgstr ""
 
-#: ../ui/patient_editor.glade.h:13
+#: ../ui/patient_editor.glade.h:16
 msgid "Codice fiscale:"
-msgstr "Código Fiscal:"
-
-#: ../ui/patient_editor.glade.h:14
-msgid "Male"
-msgstr "Masculino"
-
-#: ../ui/patient_editor.glade.h:15
-msgid "Female"
-msgstr "Feminino"
+msgstr ""
 
 #: ../ui/patient_list_sidebar.glade.h:1
 msgid "Visits"
+<<<<<<< TREE
 msgstr "Consultas"
 
 #: ../ui/patient_list_sidebar.glade.h:2
@@ -717,8 +786,14 @@
 msgstr "Agendar uma consulta"
 
 #: ../ui/doctor_editor.glade.h:5
+=======
+msgstr ""
+
+#: ../ui/doctor_editor.glade.h:1
+msgid "Create a new doctor"
+msgstr ""
+
+#: ../ui/doctor_editor.glade.h:6
+>>>>>>> MERGE-SOURCE
 msgid "Mobile:"
 msgstr "Celular:"
-
-#~ msgid "Error loading patient_editor.glade."
-#~ msgstr "Erro ao carregar patient_editor.glade."

=== modified file 'po/sr.po'
--- po/sr.po	2012-02-03 06:22:56 +0000
+++ po/sr.po	2012-02-23 21:39:18 +0000
@@ -11,12 +11,12 @@
 "PO-Revision-Date: 2011-10-21 18:52+0000\n"
 "Last-Translator: Мирослав Николић <miroslavnikolic@xxxxxxxxxxxxxx>\n"
 "Language-Team: Serbian <sr@xxxxxx>\n"
+"Language: sr\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
-"X-Launchpad-Export-Date: 2012-02-03 06:22+0000\n"
-"X-Generator: Launchpad (build 14738)\n"
-"Language: sr\n"
+"X-Launchpad-Export-Date: 2012-01-30 05:08+0000\n"
+"X-Generator: Launchpad (build 14727)\n"
 
 #: ../libclinica/Doctor.vala:110
 msgid ""
@@ -306,8 +306,8 @@
 
 #: ../libclinica/DoctorListView.vala:186
 msgid ""
-"The doctor that you have selected for removal has some patients associated. "
-"\n"
+"The doctor that you have selected for removal has some patients "
+"associated. \n"
 msgstr ""
 
 #: ../libclinica/DoctorListView.vala:187
@@ -333,8 +333,7 @@
 msgstr ""
 
 #: ../libclinica/DoctorListView.vala:244
-msgid ""
-"Really delete this doctor? All information about him/her will be lost."
+msgid "Really delete this doctor? All information about him/her will be lost."
 msgstr ""
 
 #: ../libclinica/VisitTab.vala:265

=== modified file 'po/tr.po'
--- po/tr.po	2012-02-03 06:22:56 +0000
+++ po/tr.po	2012-02-23 21:39:18 +0000
@@ -11,12 +11,12 @@
 "PO-Revision-Date: 2011-08-01 18:07+0000\n"
 "Last-Translator: zeugma <Unknown>\n"
 "Language-Team: Turkish <tr@xxxxxx>\n"
+"Language: tr\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
-"X-Launchpad-Export-Date: 2012-02-03 06:22+0000\n"
-"X-Generator: Launchpad (build 14738)\n"
-"Language: tr\n"
+"X-Launchpad-Export-Date: 2012-01-30 05:08+0000\n"
+"X-Generator: Launchpad (build 14727)\n"
 
 #: ../libclinica/Doctor.vala:110
 msgid ""
@@ -306,8 +306,8 @@
 
 #: ../libclinica/DoctorListView.vala:186
 msgid ""
-"The doctor that you have selected for removal has some patients associated. "
-"\n"
+"The doctor that you have selected for removal has some patients "
+"associated. \n"
 msgstr ""
 
 #: ../libclinica/DoctorListView.vala:187
@@ -333,8 +333,7 @@
 msgstr ""
 
 #: ../libclinica/DoctorListView.vala:244
-msgid ""
-"Really delete this doctor? All information about him/her will be lost."
+msgid "Really delete this doctor? All information about him/her will be lost."
 msgstr ""
 
 #: ../libclinica/VisitTab.vala:265


Follow ups