improvements to test suite to allow it to run from a clean repository
[openemr.git] / custom / code_types.inc.php
blob8fd3d3a32f4385b8a656730c81a6599a8d42c059
1 <?php
2 // Copyright (C) 2006-2010 Rod Roark <rod@sunsetsystems.com>
3 //
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']) {
24 // IPPF:
25 $code_types = array(
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:
35 $code_types = array(
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';
44 else {
45 // USA Clinics:
46 $code_types = array(
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() {
77 global $code_types;
78 foreach ($code_types as $value) { if ($value['fee']) return true; }
79 return false;
82 function modifiers_are_used($fee_sheet=false) {
83 global $code_types;
84 foreach ($code_types as $value) {
85 if ($fee_sheet && !empty($value['nofs'])) continue;
86 if ($value['mod']) return true;
88 return false;
91 function related_codes_are_used() {
92 global $code_types;
93 foreach ($code_types as $value) { if ($value['rel']) return true; }
94 return false;
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) {
101 global $code_types;
102 $code_text = '';
103 if (!empty($codes)) {
104 $relcodes = explode(';', $codes);
105 foreach ($relcodes as $codestring) {
106 if ($codestring === '') continue;
107 list($codetype, $code) = explode(':', $codestring);
108 $wheretype = "";
109 if (empty($code)) {
110 $code = $codetype;
111 } else {
112 $wheretype = "code_type = '" . $code_types[$codetype]['id'] . "' AND ";
114 $crow = sqlQuery("SELECT code_text FROM codes WHERE " .
115 "$wheretype code = '$code' ORDER BY id LIMIT 1");
116 if (!empty($crow['code_text'])) {
117 if ($code_text) $code_text .= '; ';
118 $code_text .= $crow['code_text'];
122 return $code_text;