Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / library / lab.inc
blob19a29a9f38d57cf5217fb11eabd631c678f9a8bc
1 <?php
2 /**
3  * lab.inc
4  *
5  * @package OpenEMR
6  * @link    http://www.open-emr.org
7  * @author  Sherwin Gaddis <sherwingaddis@gmail.com>
8  * @copyright Copyright (c) 2016-2017 Sherwin Gaddis <sherwingaddis@gmail.com>
9  * @copyright Copyright (c) 2010 OpenEMR Support LLC
10  * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
11  */
14 /**
15  * @param $pid
16  * @param $encounter
17  * @return mixed
18  */
19 function fetchProcedureId($pid, $encounter)
21     $sql = "SELECT procedure_order_id FROM procedure_order WHERE patient_id = ? AND encounter_id = ?";
22     $res = sqlQuery($sql, array($pid,$encounter));
24     return $res['procedure_order_id'];
27 /**
28  * @param $oid
29  * @param $encounter
30  * @return array
31  */
32 function getProceduresInfo($oid, $encounter)
35     $sql = "SELECT pc.procedure_order_id, pc.procedure_order_seq, pc.procedure_code, pc.procedure_name, 
36          pc.diagnoses, po.provider_id, po.date_collected,po.lab_id, po.clinical_hx, po.date_ordered, po.patient_instructions, po.specimen_type, 
37          po.specimen_location, po.specimen_volume
38      FROM procedure_order_code AS pc  
39      JOIN procedure_order AS po ON pc.procedure_order_id 
40          AND po.procedure_order_id 
41      WHERE pc.procedure_order_id = ? 
42          AND po.encounter_id = ?
43          AND po.procedure_order_id = ?";
45     $listOrders = sqlStatement($sql, array($oid,$encounter,$oid));
46     $orders = array();
47     while ($rows = sqlFetchArray($listOrders)) {
48         $orders[] = $rows['procedure_order_id'];
49         $orders[] = $rows['procedure_order_seq'];
50         $orders[] = $rows['procedure_code'];
51         $orders[] = $rows['procedure_name'];
52         $orders[] = $rows['diagnoses'];
53         $orders[] = $rows['provider_id'];
54         $orders[] = $rows['date_collected'];
55         $orders[] = $rows['lab_id'];            //procedure_order.ppid
56         $orders[] = $rows['clinical_hx'];
57         $orders[] = $rows['date_ordered'];
58         $orders[] = $rows['patient_instructions'];
59         $orders[] = $rows['specimen_type'];
60         $orders[] = $rows['specimen_location'];
61         $orders[] = $rows['specimen_volume'];
62     }
64     return $orders;
67 /**
68  * @param $pid
69  * @return mixed
70  */
72 function getSelfPay($pid)
74     $sql = "SELECT subscriber_relationship FROM insurance_data WHERE pid = ?";
75     $res = sqlQuery($sql, array($pid));
77     return $res['subscriber_relationship'];
80 /**
81  * @param $prov_id
82  * @return array
83  */
84 function getNPI($prov_id)
86     $sql = "SELECT npi, upin FROM users WHERE id = ?";
87     $res = sqlQuery($sql, array($prov_id));
88     return array($res['npi'], $res['upin']);
91 /**
92  * @return array
93  */
94 function getProcedureProvider($prov_id)
96     $sql = "SELECT i.organization, i.street, i.city, i.state, i.zip, i.fax, i.phone, pi.lab_director ".
97            "FROM users AS i, procedure_providers AS pi WHERE pi.ppid = ? AND pi.lab_director = i.id ";
99     $res = sqlStatement($sql, array($prov_id));
100     $labs = sqlFetchArray($res);
102     return $labs;
106  * @param $prov_id
107  * @return array|null
108  */
109 function getLabProviders($prov_id)
112     $sql = "select fname, lname from users where authorized = 1 and active = 1 and username != '' and id = ?";
113     $rez = sqlQuery($sql, array($prov_id));
116     return $rez;
120 * This is going to be adjusted when there is more than one provider.
122 function getLabconfig()
124     $sql = "SELECT recv_app_id, recv_fac_id FROM procedure_providers ";
125     $res = sqlQuery($sql);
126     return $res;
129 function saveBarCode($bar, $pid, $order)
131     $sql = "INSERT INTO `requisition` (`id`, `req_id`, `pid`, `lab_id`) VALUES (NULL, ?, ?, ?)";
132     $inarr = array($bar,$pid,$order);
133     sqlStatement($sql, $inarr);
136 function getBarId($lab_id, $pid)
138     $sql = "SELECT req_id FROM requisition WHERE lab_id = ? AND pid = ?";
139     $bar = sqlQuery($sql, array($lab_id,$pid));
141     return $bar;
146  * @param <type> $facilityID
147  * @return <type> the result set, false if the input is malformed
148  */
149 function getFacilityInfo($facilityID)
151     // facility ID will be in the format XX_YY, where XX is the lab-assigned id, Y is the user.id record representing that lab facility, and the _ is a divider.
152     $facility = explode("_", $facilityID);
154     if (count($facility) > 1) {
155         $query = "SELECT title, fname, lname, street, city, state, zip, organization, phone FROM users WHERE id = ?";
157         $res = sqlStatement($query, array($facility[1]));
158         return sqlFetchArray($res);
159     }
161     return false;
164 function formatPhone($phone)
166     $phone = preg_replace("/[^0-9]/", "", $phone);
167     if (strlen($phone) == 7) {
168         return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
169     } elseif (strlen($phone) == 10) {
170         return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
171     } else {
172         return $phone;
173     }