Setting Up the HealthViews Batch Process

Topics:

HealthViews is implemented using a batch of SQL scripts that retrieve data from the omnihealthdata database and denormalize the data. The running of the scripts is automated through a shell script, build_all.sh.

The script first configures variables:

L_PROGNAME=$(basename $0)
L_DB_CONFIG=db_config/postgresql.properties
L_TEMPFILE=$(mktemp /tmp/healthviews-XXXX)
L_SQL_FILES=$(\ls *.sql)

The script assumes that the configuration file will be located in a subdirectory named db_config. Change this value if a different directory is used. It also gets a list of all SQL scripts in the current directory. The scripts are processed in order later in the script:

echo "start: ${L_SQL_FILE} $(date)"
psql -h ${database_host} -U ${database_username} -d ${database_name}
-q -f ${L_TEMPFILE}
echo "end: ${L_SQL_FILE} $(date)"

The two echo statements are used to create log file entries. The script then calls each HealthViews script and executes it.

Installing the HealthViews Scripts

All HealthViews scripts, as well as build_all.sh should be installed in the same directory. It is recommended to use a separate directory for each database instance to be supported (DEV, PROD, QA, and so on).

Configuring the HealthViews Process

A configuration file, postgresql.properties, is used to configure the HealthViews batch process. This file should be located in a \db_config directory, under the main HealthViews directory.

The settings are as follows:

database.type=the type of database.  Should be set to POSTGRESQL
database.host=the location of the database server.  Can be either a 
logical name or a dotted IP address.
database.name=the name of the database for OmniHealthData and 
HealthViews.
database.username=the user name to log in to the database with.
database.src_schema=the schema for OmniHealthData.  Typically public.
database.targ_schema=the schema for HealthViews.  Typically healthviews.

Executing the Scripts

The build_all.sh file takes a directory listing of every .sql script in the current directory and runs them in order, using the configuration information defined above. Scripts are run singly, no scripts run concurrently.

To execute the scripts, navigate to the directory containing build_all.sh and the HealthViews scripts. At the prompt, type:

./build_all.sh &> [logfile_name].log

It is recommended to pipe the output of build_all.sh (including stderr) to a log file so that any errors can be noted and debugged.

Automating the HealthViews Process

Generally, the HealthViews batch process is manually run on a regular basis. To automate this, use a cron job to schedule the running of the build_all.sh. For example:

[hv_user@hv_machine]$ crontab –e

opens the crontab for the current user for editing

01 00 * * 1,2,3,4,5 * \hv_dir\build_all.sh &> hv_dir/log/
build_healthviews.${L_TODAY}.log)

This creates a job scheduled to run at 12:01 AM every Monday, Tuesday, Wednesday, Thursday, and Friday with a log created with the date of the log in the file name in a \log directory. The first two digits (01) represent the minutes, the second two (00) represent the hour (using a 24-hour clock), the two consecutive asterisks indicate the job should be executed all months and all days of the month, the 1,2,3,4,5 represent the days of the week (Sunday is represented by either 0 or 7), and the final asterisk indicates the job should run all years. The entry then gives the command to be run, including sending the output to a log file.