# OpenClinica User Manual/OfflineDistributions
## Using Python Script to Create Subjects and Schedule OpenClinica Events

DNDi Data Center in Nairobi, Kenya has been exploring ways of using OpenClinica in “offline mode” and has developed a python Script which makes it possible to use the software in offline mode then later synchronize with a central database. The script is meant to work in an environment which is organized as follows;
1. First the Central database is setup on a main study server. Create the final version of the study database and define study sites and site users. This becomes the main or central study database and in this case is hosted at the DNDi Data Center Server in Nairobi. When this is done, we use the final study database dump to replicate the database on all site computers.
2. Proceed to collect data at the sites Once the database is installed on the site computers, the site users can proceed with data entry normally. No internet connection is needed since OpenClinica is locally installed on the site computers. Data is then periodically extracted from the study computers in CDISC ODM 1.3 Xml format and sent to DNDi Data Center in Nairobi for import into the Central database. Latest database dump is also generated and sent to Data Center.
3. Synchronization with the Central Study database at the Data Center. When the Data Center receives both the extracted data and the latest database dump, the latest database dump is plugged into Postgres database on the same server as the Central study database. This means that a database “using site name” is created on the same server as central database and site database dump restored on it. A python (see http://www.python.org) script which is referred to as OC Event Scheduler is executed. The script compares the Central database with the plugged-in site database, checking whether the subjects available in the site database are also available in the Central database. If the subjects are not available in the central database then they are created in the central database. The Script also checks whether the subjects events from the site database have been scheduled in the Central database, and if not, then the events are scheduled. Once new subjects are added and all events scheduled, then the extracted site data is then imported using OpenClinica data import functionality. The data import can either be done manually or an import task can be scheduled such that OpenClinica will then import all the ODM files posted on the import folder as scheduled.
OC Event Scheduler is a generic tool which is only “supplied” with the central database name, site database name, database username, database host address, and the database password in order to be used to synchronize the site and the central database.
Python Script Installation
To execute the script, the following software must be installed;
1. Apart from standard OpenClinica software stack, Python Software (from http://www.python.org/download/releases/2.7.2/) must be installed in order to execute the OC Event Scheduler script.
2. Psycopg2 (PostgreSQL database adapter for the Python programming language) is available for download from http://initd.org/pub/software/psycopg2 and also http://www.stickpeople.com/projects/python/win-psycopg/ for Windows.
Additional details on how the script works is available on the Script as comments.