fix: ccda zip import and php warnings and deprecations (#7416)
[openemr.git] / library / contraception_billing_scan.inc.php
blob7a5c673c2f78baa54474967b2f4e83a1adcc7395
1 <?php
3 /**
4 * Copyright (C) 2012-2021 Rod Roark <rod@sunsetsystems.com>
6 * LICENSE: This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
17 * @package OpenEMR
18 * @link http://www.open-emr.org
21 use OpenEMR\Billing\BillingUtilities;
23 // These variables are used to compute the service with highest CYP.
25 $contraception_billing_code = '';
26 $contraception_billing_cyp = -1;
27 $contraception_billing_prov = 0;
29 // This is called for each service in the visit to determine the method
30 // of the service with highest CYP.
32 function _contraception_billing_check($code_type, $code, $provider)
34 global $code_types;
35 global $contraception_billing_code, $contraception_billing_cyp, $contraception_billing_prov;
37 if ($code_type != 'MA') {
38 return;
41 // The cyp_factor test in this query is to select only MA codes that
42 // are flagged as Initial Consult.
43 $sql = "SELECT related_code FROM codes WHERE " .
44 "code_type = ? AND code = ? AND cyp_factor != 0 LIMIT 1";
45 $codesrow = sqlQuery($sql, array($code_types[$code_type]['id'], $code));
47 if (!empty($codesrow['related_code'])) {
48 $relcodes = explode(';', $codesrow['related_code']);
49 foreach ($relcodes as $relstring) {
50 if ($relstring === '') {
51 continue;
53 list($reltype, $relcode) = explode(':', $relstring);
54 if ($reltype !== 'IPPFCM') {
55 continue;
57 $tmprow = sqlQuery(
58 "SELECT cyp_factor FROM codes WHERE " .
59 "code_type = '32' AND code = ? LIMIT 1",
60 array($relcode)
62 $cyp = 0 + $tmprow['cyp_factor'];
63 if ($cyp > $contraception_billing_cyp) {
64 $contraception_billing_cyp = $cyp;
65 $contraception_billing_code = $relcode;
66 $contraception_billing_prov = $provider;
72 // Get the contraceptive method (IPPFCM) code $contraception_billing_code, if any,
73 // indicated by an initial-consult contraception service in the visit. If
74 // there is more than one then the code with highest CYP is selected. This
75 // call returns TRUE if one is found, otherwise FALSE. Also set is the
76 // provider of that service, $contraception_billing_prov, and the corresponding
77 // CYP value $contraception_billing_cyp.
79 function contraception_billing_scan($patient_id, $encounter_id, $provider_id = 0)
81 global $contraception_billing_code, $contraception_billing_cyp, $contraception_billing_prov;
83 $contraception_billing_code = '';
84 $contraception_billing_cyp = -1;
85 $contraception_billing_prov = 0;
87 $billresult = BillingUtilities::getBillingByEncounter($patient_id, $encounter_id, "*");
88 if (is_array($billresult)) {
89 foreach ($billresult as $iter) {
90 _contraception_billing_check($iter["code_type"], trim($iter["code"]), $iter['provider_id']);
93 // If no provider at the line level, use the encounter's default provider.
94 if (empty($contraception_billing_prov)) {
95 $contraception_billing_prov = 0 + $provider_id;
97 if (!empty($contraception_billing_code)) {
98 return true;
100 return false;