2 // Copyright (C) 2006-2010 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This array provides abstraction of billing code types. This is desirable
10 // because different countries or fields of practice use different methods for
11 // coding diagnoses, procedures and supplies. Fees will not be relevant where
12 // medical care is socialized. Attribues are:
14 // id - the numeric identifier of this code type in the codes table
15 // fee - 1 if fees are used, else 0
16 // mod - the maximum length of a modifier, 0 if modifiers are not used
17 // just - the code type used for justification, empty if none
18 // rel - 1 if other billing codes may be "related" to this code type
19 // nofs - 1 if this code type should NOT appear in the Fee Sheet
20 // diag - 1 if this code type is for diagnosis
22 /*********************************************************************
23 if ($GLOBALS['ippf_specific']) {
26 'ICD9' => array('id' => 2, 'fee' => 0, 'mod' => 0, 'just' => '', 'rel' => 0, 'nofs' => 0, 'diag' => TRUE),
27 'MA' => array('id' => 12, 'fee' => 1, 'mod' => 0, 'just' => '', 'rel' => 1, 'nofs' => 0),
28 'IPPF' => array('id' => 11, 'fee' => 0, 'mod' => 0, 'just' => '', 'rel' => 0, 'nofs' => 1),
29 'ACCT' => array('id' => 13, 'fee' => 0, 'mod' => 0, 'just' => '', 'rel' => 0, 'nofs' => 1),
31 $default_search_type = 'MA';
33 else if ($GLOBALS['athletic_team']) {
34 // UK Sports Medicine:
36 'OSICS10' => array('id' => 9, 'fee' => 0, 'mod' => 4, 'just' => '', 'rel' => 0, 'nofs' => 0, 'diag' => TRUE),
37 'OPCS' => array('id' => 6, 'fee' => 0, 'mod' => 0, 'just' => '', 'rel' => 0, 'nofs' => 0),
38 'PTCJ' => array('id' => 7, 'fee' => 0, 'mod' => 0, 'just' => '', 'rel' => 0, 'nofs' => 0),
39 'CPT4' => array('id' => 1, 'fee' => 0, 'mod' => 0, 'just' => '', 'rel' => 0, 'nofs' => 0),
40 'SMPC' => array('id' => 10, 'fee' => 0, 'mod' => 0, 'just' => '', 'rel' => 0, 'nofs' => 0),
42 $default_search_type = 'OSICS10';
47 'ICD9' => array('id' => 2, 'fee' => 0, 'mod' => 2, 'just' => '' , 'rel' => 0, 'nofs' => 0, 'diag' => TRUE),
48 'CPT4' => array('id' => 1, 'fee' => 1, 'mod' => 2, 'just' => 'ICD9', 'rel' => 0, 'nofs' => 0),
49 'HCPCS' => array('id' => 3, 'fee' => 1, 'mod' => 2, 'just' => 'ICD9', 'rel' => 0, 'nofs' => 0),
51 $default_search_type = 'ICD9';
53 *********************************************************************/
55 // Code types are now stored in the database.
57 $code_types = array();
58 $default_search_type = '';
59 $ctres = sqlStatement("SELECT * FROM code_types ORDER BY ct_seq, ct_key");
60 while ($ctrow = sqlFetchArray($ctres)) {
61 $code_types[$ctrow['ct_key']] = array(
62 'id' => $ctrow['ct_id' ],
63 'fee' => $ctrow['ct_fee' ],
64 'mod' => $ctrow['ct_mod' ],
65 'just' => $ctrow['ct_just'],
66 'rel' => $ctrow['ct_rel' ],
67 'nofs' => $ctrow['ct_nofs'],
68 'diag' => $ctrow['ct_diag'],
69 'mask' => $ctrow['ct_mask'],
71 if ($default_search_type === '') $default_search_type = $ctrow['ct_key'];
74 /********************************************************************/
76 function fees_are_used() {
78 foreach ($code_types as $value) { if ($value['fee']) return true; }
82 function modifiers_are_used($fee_sheet=false) {
84 foreach ($code_types as $value) {
85 if ($fee_sheet && !empty($value['nofs'])) continue;
86 if ($value['mod']) return true;
91 function related_codes_are_used() {
93 foreach ($code_types as $value) { if ($value['rel']) return true; }
97 // Look up descriptions for one or more billing codes. Input is of the
98 // form "type:code;type:code; etc.".
100 function lookup_code_descriptions($codes) {
103 if (!empty($codes)) {
104 $relcodes = explode(';', $codes);
105 foreach ($relcodes as $codestring) {
106 if ($codestring === '') continue;
107 list($codetype, $code) = explode(':', $codestring);
113 $wheretype = "code_type = ? AND ";
114 array_push($sqlArray,$code_types[$codetype]['id']);
116 $sql = "SELECT code_text FROM codes WHERE " .
117 "$wheretype code = ? ORDER BY id LIMIT 1";
118 array_push($sqlArray,$code);
119 $crow = sqlQuery($sql,$sqlArray);
120 if (!empty($crow['code_text'])) {
121 if ($code_text) $code_text .= '; ';
122 $code_text .= $crow['code_text'];