4 * library/daysheet.inc.php Functions used in the end of day report.
6 * Functions for Generating an End of Day report
9 * Copyright (C) 2014-2015 Terry Hill <terry@lillysystems.com>
11 * LICENSE: This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
23 * @author Terry Hill <terry@lillysystems.com>
24 * @link https://www.open-emr.org
28 * @return Returns the array sorted as required
29 * @param $aryData Array containing data to sort
30 * @param $strIndex Name of column to use as an index
31 * @param $strSortBy Column to sort the array by
32 * @param $strSortType String containing either asc or desc [default to asc]
33 * @desc Naturally sorts an array using by the column $strSortBy
36 use OpenEMR\Billing\BillingReport
;
38 function array_natsort($aryData, $strIndex, $strSortBy, $strSortType = false)
40 // if the parameters are invalid
41 if (!is_array($aryData) ||
!$strIndex ||
!$strSortBy) {
46 // create our temporary arrays
47 $arySort = $aryResult = array();
48 // loop through the array
49 foreach ($aryData as $aryRow) {
50 // set up the value in the array
51 $arySort[$aryRow[$strIndex]] = $aryRow[$strSortBy];
54 // apply the natural sort
56 // if the sort type is descending
57 if ($strSortType == "desc") {
62 // loop through the sorted and original data
63 foreach ($arySort as $arySortKey => $arySorted) {
64 foreach ($aryData as $aryOriginal) {
66 if ($aryOriginal[$strIndex] == $arySortKey) {
67 // add it to the output array
68 array_push($aryResult, $aryOriginal);
77 // date must be in nice format (e.g. 2002-07-11)
78 function getBillsBetweendayReport(
80 $cols = "id,date,pid,code_type,code,user,authorized,x12_partner_id"
83 BillingReport
::GenerateTheQueryPart($daysheet = true);
84 global $query_part,$query_part2,$query_part_day,$query_part_day1,$billstring,$auth;
86 $sql = "SELECT distinct form_encounter.pid AS enc_pid, form_encounter.date AS enc_date, concat(lname, ' ', fname) as 'fulname', lname as 'last', fname as 'first', " .
87 "form_encounter.encounter AS enc_encounter, form_encounter.provider_id AS enc_provider_id, billing.* , date(billing.date) as date " .
88 "FROM form_encounter " .
89 "LEFT OUTER JOIN billing ON " .
90 "billing.encounter = form_encounter.encounter AND " .
91 "billing.pid = form_encounter.pid AND " .
92 "billing.code_type LIKE ? AND " .
93 "billing.activity = 1 " .
94 "LEFT OUTER JOIN patient_data ON patient_data.pid = form_encounter.pid " .
95 "LEFT OUTER JOIN claims on claims.patient_id = form_encounter.pid and claims.encounter_id = form_encounter.encounter " .
96 "LEFT OUTER JOIN insurance_data on insurance_data.pid = form_encounter.pid and insurance_data.type = 'primary' " .
97 "WHERE 1=1 $query_part AND billing.fee!=0 " . " $auth " . " $billstring " .
98 "ORDER BY fulname ASC, date ASC, pid ";
100 $res = sqlStatement($sql, array($code_type));
102 for ($iter = 0; $row = sqlFetchArray($res); $iter++
) {
106 $query = sqlStatement("SELECT ar_activity.pid as pid, 'Patient Payment' AS code_type, ar_activity.pay_amount AS pat_code, date(ar_activity.post_time) AS date," .
107 "ar_activity.encounter AS encounter_ar, concat(lname, ' ', fname) as 'fulname', lname as 'last', fname as 'first', ar_activity.payer_type AS payer," .
108 "ar_activity.session_id AS sesid, ar_activity.account_code AS paytype, ar_activity.post_user AS user, ar_activity.memo AS reason," .
109 "ar_activity.adj_amount AS pat_adjust_dollar, providerid as 'provider_id' " .
110 "FROM ar_activity LEFT OUTER JOIN patient_data ON patient_data.pid = ar_activity.pid " .
111 "WHERE ar_activity.deleted IS NULL $query_part_day AND payer_type = 0 ORDER BY fulname ASC, date ASC, pid");
113 for ($iter; $row = sqlFetchArray($query); $iter++
) {
117 $query = sqlStatement("SELECT ar_activity.pid as pid, 'Insurance Payment' AS code_type, ar_activity.pay_amount AS ins_code, date(ar_activity.post_time) AS date," .
118 "ar_activity.encounter AS encounter_ar, concat(lname, ' ', fname) as 'fulname', lname as 'last', fname as 'first', ar_activity.payer_type AS payer," .
119 "ar_activity.session_id AS sesid, ar_activity.account_code AS paytype, ar_activity.post_user AS user, ar_activity.memo AS reason," .
120 "ar_activity.adj_amount AS ins_adjust_dollar, providerid as 'provider_id' " .
121 "FROM ar_activity LEFT OUTER JOIN patient_data ON patient_data.pid = ar_activity.pid " .
122 "WHERE ar_activity.deleted IS NULL $query_part_day AND payer_type != 0 ORDER BY fulname ASC, date ASC, pid");
124 for ($iter; $row = sqlFetchArray($query); $iter++
) {