You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.4 KiB

2 years ago
<?php
/**
*
* @package OpenEMR
* @link
* @author Ken Schaefer <kschaefer@harmonyhealthmedical.com>
* @copyright Copyright (c) 2022 Ken Schaefer
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
class Billing
{
public function getARActivity($biller_id, $from_date, $to_date)
{
$query = "
SELECT
r.encounter, r.code, r.modifier, r.post_time, r.post_user, r.pay_amount, r.adj_amount,
(SELECT CONCAT(lname, ', ', fname) FROM users AS u WHERE r.post_user = u.id) AS username,
fe.date AS dos, fe.pid, fe.provider_id, b.billed, b.bill_date,
(SELECT CONCAT(lname, ', ', fname) FROM patient_data AS p WHERE p.pid = fe.pid) AS patient_name
FROM openemr.ar_activity AS r
LEFT JOIN form_encounter AS fe ON r.encounter = fe.encounter
LEFT JOIN (SELECT * FROM billing WHERE id IN (SELECT MIN(id) FROM billing GROUP BY encounter)) AS b ON fe.encounter = b.encounter
WHERE r.post_time BETWEEN '" . $from_date . "' AND '" . $to_date . "' AND
r.deleted IS NULL
";
if($biller_id != 0) {
$query = $query . " AND r.post_user = " . $biller_id;
}
$query = $query . " ORDER BY r.post_user, r.post_time DESC";
return $query;
}
}