#!/bin/ksh
#
#-------------------------------------------------------------------
# Function: monitorcopy logtype username patientID
#
# Usage:
#   monitorcopy extract username patientID
#
#   monitorcopy capture username patientID
#
#
# Purpose: Transfer mojoe logs and prepare them for sending
# to the mojoe_monitor
#
#-------------------------------------------------------------------
#===================================================================
# C H A N G E   L O G
#
# KLP	10/31/06	created
#===================================================================
#
#
logtype=${1:-extract}
username=${2:-mojoe}
patientID=${3:-patient}
#
#-------------------------------------------------------------------
# BEGIN ... VARIABLE SETTINGS
#
#monitorLocalDir=/export/home/sdc/mojoe/log/monitorlog
mojoe_dir=$MOJOE_DIR
if (test ${#mojoe_dir} -lt 1)
    then
    mojoe_dir=$HOME/mojoe
fi
monitorLocalDir=$mojoe_dir/log/monitorlog
#
#-------------------------------------------------------------------
#
cwd=$PWD

cd $monitorLocalDir
fname=monitor_$logtype.log
#
# for capture, copy ../../info/general.sinfo to monitor_capture.log
#
# if it doesn't exist, get ../../mojoe_capture.log instead
#
if (test $logtype = 'capture') then
    logname=../../info/mojoe_general.sinfo
    if (test -f $logname && test -s $logname) then
        cp -p $logname $fname
    else
        logname=../../mojoe_$logtype.log
        if (test -f $logname && test -s $logname) then
            cp -p $logname $fname
        fi
    fi
fi
#
# for extract, copy mojoe_extract.sinfo to monitor_capture.log
# (saved here at the end of properly completed extract1 script)
#
# if it doesn't exist, get ../../mojoe_capture.log instead
#
if (test $logtype = 'extract') then
    logname=mojoe_extract.sinfo
    if (test -f $logname && test -s $logname) then
        mv $logname $fname
    else
        logname=../../mojoe_$logtype.log
        if (test -f $logname && test -s $logname) then
            cp -p $logname $fname
        fi
    fi
fi
if (! test -f $fname) then
    datestr=`date '+%H:%M:%S %m/%d/%y'`
    echo $datestr $logtype $username $patientID ... no log present >> monitor.log
    return
fi
datestr=`date '+%H_%M_%S_%m_%d_%y'`
echo ScannerHost: $HOSTNAME > scanhost.txt
fname2=$HOSTNAME'_'$logtype'_'$username'_'$patientID'_'$datestr.txt
cat scanhost.txt $fname > $fname2
rm -f scanhost.txt
rm -f $fname
cd $cwd
