Add claimrev module (#6280)
[openemr.git] / interface / modules / custom_modules / oe-module-claimrev-connect / src / ReportDownload.php
blob8531b8bc5c80079c7f148c8d2b74eed4c7c80e5c
1 <?php
3 /**
5 * @package OpenEMR
6 * @link http://www.open-emr.org
8 * @author Brad Sharp <brad.sharp@claimrev.com>
9 * @copyright Copyright (c) 2022 Brad Sharp <brad.sharp@claimrev.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 namespace OpenEMR\Modules\ClaimRevConnector;
15 use OpenEMR\Services\BaseService;
16 use OpenEMR\Modules\ClaimRevConnector\ClaimRevApi;
18 class ReportDownload extends BaseService
20 public static function getWaitingFiles()
22 $reportTypes = array("999", "277", "835");
23 $siteDir = $GLOBALS['OE_SITE_DIR'];
24 //should be something like '/var/www/localhost/htdocs/openemr/sites/default'
26 $token = ClaimRevApi::GetAccessToken();
27 foreach ($reportTypes as $reportType) {
28 $reportFolder = "f" . $reportType;
29 if ($reportType == "999") {
30 $reportFolder = "f997";
33 $savePath = $siteDir . '/documents/edi/history/' . $reportFolder . '/';
35 //$savePath = $siteDir . '/documents/edi/';
36 if (!file_exists($savePath)) {
37 // Create a direcotry
38 mkdir($savePath, 0777, true);
41 $datas = ClaimRevApi::getReportFiles($reportType, $token);
42 if (is_array($datas)) {
43 foreach ($datas as $data) {
44 if (property_exists($data, 'fileText')) {
45 $fileText = $data->fileText;
46 $fileName = $data->fileName ;
47 $filePathName = $savePath . $fileName . '.txt';
48 file_put_contents($filePathName, $fileText);
49 chmod($filePathName, 0777);
50 } else {
51 error_log("Unable to find property FileText in ClaimRevConnector.ReportDownload.getWaitingFiles");