script to install and configure cvs demo
[openemr.git] / library / DBC_cron.php
blobec06f0a5fe418f106476baff615a008ec7705228
1 <?php
2 /** DBC DUTCH SYSTEM
3 * Cron only functions
4 *
5 * @author Cristian NAVALICI (lemonsoftware [..] gmail [.] com)
6 * @version 1.0
7 */
9 require_once('DBC_cfunctions.php');
10 require_once('DBC_functions.php');
11 require_once('DBC_decisiontree.php');
12 require_once('DBC_validations.php');
14 dc_yearly_closing();
16 // ----------------------------------------------------------------------------
17 /**
20 @param
21 @return
23 function dc_yearly_closing() {
24 dc_connect();
25 global $rfsum;
27 // take all opened DBC
28 $r = mysql_query("SELECT * FROM cl_axes ca JOIN cl_careroute_numbers ccn ON ca.ax_ztn = ccn.cn_ztn
29 WHERE ca.ax_open = 1");
31 while ( $row = mysql_fetch_array($r) ) {
32 $pid = $row['cn_pid'];
33 $dbcid = $row['ax_id'];
34 $today = date('Y-m-d');
36 // and calculate the age
37 $age = df_dbc_age($dbcid);
38 if ( $age >= 365 ) {
39 $rfsum = 0; // reset the rfsum!
40 dt_main(1, $dbcid, $odate);
41 $z = dt_whatproductgroep($rfsum, $odate);
42 $pcode = $z['id'];
44 $gafstr = unserialize($row['ax_as5']);
45 $gaf['gaf1'] = $gafstr['gaf1'];
46 $gaf['gaf2'] = preg_replace('/_01/', '_02', $gaf['gaf1']);
47 $gaf['gaf3'] = preg_replace('/_01/', '_03', $gaf['gaf1']);
49 $lastenc = last_encounter($pid);
51 $fe = future_events($pid, $today); // any future events after today?
53 $have_followup = ( $fe ) ? 1 : 0;
55 echo "$pid($dbcid) - $fe - LAST: {$lastenc['date']} F: $have_followup\n";
56 $newid = close_dbc($have_followup, $pcode, '180101', '110003', $gaf, $dbcid, $today, $pid);
58 if ( $newid ) {
59 df_cronlog("$today: DBC id: $dbcid (PID: $pid) was duplicated with DBC id: $newid ");
60 } else {
61 df_cronlog("$today: DBC id: $dbcid (PID: $pid) was closed without a followup. ");
67 //-----------------------------------------------------------------------------
68 /**
69 CONNECT TO DATABASE
71 make the connections to openemr database
72 the variables are taken from sqlconf.php
74 @param none
75 @return void
77 function dc_connect() {
78 require_once(dirname(__FILE__) . '/sqlconf.php');
79 global $host, $login, $pass, $dbase;
81 $link = mysql_connect($host, $login, $pass);
82 if (!$link) {
83 die('Could not connect: ' . mysql_error());
86 mysql_query("USE " . $dbase);