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
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'];
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));
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'];
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'];
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']);
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);
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));
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);
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));
146 * @param <type> $facilityID
147 * @return <type> the result set, false if the input is malformed
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);
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);