SRFax Gateway
Logs will be in the root home directory with one line per fax that should look something like
Sat Feb 29 07:05:06 EST 2020 fax to <fax no> {"Status":"Success","Result":<SRfaxserial>} for prescription_<user><OSCAR serial>.txt
Using the API to Download your Faxes
This is a preferred method that accesses the SRfax api directly. Lets set up some php code into a file and call it srfax2o.php saving it to /usr/share/oscar-emr/php-oscar-srfax/srfax2o.php. Note the dependency of srfax.php which is a php class available for free from SRFax (as its copyright is not clear it is not reproduced here)
Ensure to set the Sender settings at the top of the script with your credentials for your SRfax account.
<?php /* START: Example configuration */ $API_URL = 'https://www.srfax.com/SRF_SecWebSvc.php'; // Set these options with your credentials // Sender settings $API_USER = ''; // put your number ID of your main SRFAX account, ie, 123456 $API_PASS = ''; // your master account password $SENDER_FAX = ''; // your fax number 5555551212 etc $SENDER_EMAIL = ''; // email associated with srfax account /* END: Example configuration */ $script_dir = "/usr/share/oscar-emr/php-oscar-srfax"; require_once "$script_dir/srfax.php"; //require_once "srfax.php"; $short_options = 'h'; $long_options = array( 'help' => 'Show this help screen', 'func:' => 'Name of func to run (required)', 'id::' => 'FaxDetailsID to use for func (if applicable)', 'file::' => 'File to use for input to send a fax (if applicable)', 'viewed::' => 'Viewed state to set for fax - Y or N (if applicable)', 'dir::' => 'Direction to use for func - IN or OUT (if applicable)'); // Get our command line options & validate required items $options = getopt($short_options, array_keys($long_options)); if(isset($options['h']) || isset($options['help']) || !isset($options['func'])) { echo("\n"); echo("This tool is used to run examples of the SRFax API lib. Options are as follows\n "); foreach($long_options as $name => $message) { $name = str_replace(':', '', $name); echo( "\t--$name=$message\n" ); } echo("\n"); exit(); } $func = $options['func']; $id = isset($options['id']) ? $options['id'] : null; $file = isset($options['file']) ? $options['file'] : null; $viewed = isset($options['viewed']) ? $options['viewed'] : null; $dir = isset($options['dir']) ? $options['dir'] : null; $out = ''; $oscar_fax_dir = '/usr/share/oscar-emr/OscarDocument/oscar/incomingdocs/1/Fax'; // Initialize srfax $srfax = new srfax($API_USER, $API_PASS, $API_URL, $SENDER_FAX, $SENDER_EMAIL); // Get the fax inbox if($func == 'oscar-inbox') { $test = $srfax->Get_Fax_Inbox(); foreach($test as $message) { foreach($message as $key => $value) { if ($key == "FileName") { $targetFile = $value; } if (($key == "ViewedStatus") && ($value == "N")) { $splitTargetFile = explode ("|", $targetFile); $targetID = $splitTargetFile[1]; echo "downloading $targetFile - ID $targetID\n"; try { $action = $srfax->Retrieve_Fax("IN", $targetID); if(!empty($action)) { file_put_contents("$oscar_fax_dir/$targetID.pdf", $action); echo "Successfully retrieved file as $oscar_fax_dir/$targetID.pdf"; //set viewed try { $action = $srfax->Update_Viewed_Status("IN", "Y", $targetID); echo "Fax set to viewed\n"; } catch (Exception $e) { $out = "Error: " . $e->getMessage(); } } } catch (Exception $e) { $out = "Error: " . $e->getMessage(); } } } } } echo "$out\n"; exit(0); ?>
You will need a wrapper to call the php script. Lets call it faxwrap.sh
#! /bin/bash php /usr/share/oscar-emr/php-oscar-srfax/srfax2o.php --func=oscar-inbox >> /usr/share/oscar-emr/php-oscar-srfax/php-oscar-srfax.log 2>&1 chown -R tomcat9:tomcat9 /usr/share/oscar-emr/OscarDocument/oscar/incomingdocs/1/Fax/
And set it up as a cron job (you will need to run it as root or the tomcat user to open the files that are dropped by Oscar into the tmp directory.) The following example has the root user sending the files
sudo crontab -e
And add an entry like the following that executes every 2 minutes
*/2 * * * * /usr/share/oscar-emr/php-oscar-srfax/faxwrap.sh