Merge pull request #1492 from matrix-israel/fix_dated_reminders
[openemr.git] / library / MedEx / MedEx_background.php
blob3246147b741c089c00cc2e3ddbaea2500aa023a9
1 <?php
2 /**
3 * /library/MedEx/medex_background.php
5 * This file is executed as a background service. It synchronizes data with MedExBank.com,
6 * delivering events to be processed to MedEx AND receiving message outcomes from MedEx.
7 * MedEx.php receives data synchronously - when a response is received at MedExBank.com, the practice receives
8 * that information directly. However not every server is always online.
9 * MedEx_background.php receives message reponses asynchronously. It checks for all messages received since it was last
10 * executed (+ another 24 hours to be sure) and if any new ones are found,
11 * it adds them to the local database (medex_outgoing table).
13 * MedEx_background: manually set execution frequency in DB table "background services".
14 * Suggest running this file every 29 minutes (default) or less frequently,
15 * but at least once each morning before 8AM localtime on work days.
16 * eg. every 29 minutes ==> active=1, execute_interval=29 (default installed values)
17 * four times a day ==> active=1, execute_interval=360 (60 minutes x 6)
19 * @package MedEx
20 * @link http://www.MedExBank.com
21 * @author MedEx <support@MedExBank.com>
22 * @copyright Copyright (c) 2017 MedEx <support@MedExBank.com>
23 * @license https://www.gnu.org/licenses/agpl-3.0.en.html GNU Affero General Public License 3
26 $ignoreAuth=true;
28 require_once(dirname(__FILE__)."/../../interface/globals.php");
29 require_once(dirname(__FILE__)."/API.php");
30 require_once(dirname(__FILE__)."/../patient.inc");
31 require_once(dirname(__FILE__)."/../log.inc");
33 function start_MedEx()
35 $MedEx = new MedExApi\MedEx('MedExBank.com');
36 $logged_in = $MedEx->login();
37 if ($logged_in) {
38 $token = $logged_in['token'];
39 $MedEx->practice->sync($token);
40 $campaigns = $MedEx->campaign->events($token);
41 $MedEx->events->generate($token, $campaigns['events']);
42 echo "200";
43 } else {
44 echo $MedEx->getLastError();
46 echo "401";