7 * @link http://www.open-emr.org
8 * @author Sherwin Gaddis <sherwingaddis@gmail.com>
9 * @copyright Copyright (c) 2016-2017 Sherwin Gaddis <sherwingaddis@gmail.com>
10 * @copyright Copyright (c) 2010 OpenEMR Support LLC
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
20 function fetchProcedureId($pid, $encounter)
22 $sql = "SELECT procedure_order_id FROM procedure_order WHERE patient_id = ? AND encounter_id = ?";
23 $res = sqlQuery($sql, array($pid,$encounter));
25 return $res['procedure_order_id'];
33 function getProceduresInfo($oid, $encounter)
36 $sql = "SELECT pc.procedure_order_id, pc.procedure_order_seq, pc.procedure_code, pc.procedure_name,
37 pc.diagnoses, po.provider_id, po.date_collected,po.lab_id, po.clinical_hx, po.date_ordered, po.patient_instructions, po.specimen_type,
38 po.specimen_location, po.specimen_volume
39 FROM procedure_order_code AS pc
40 JOIN procedure_order AS po ON pc.procedure_order_id
41 AND po.procedure_order_id
42 WHERE pc.procedure_order_id = ?
43 AND po.encounter_id = ?
44 AND po.procedure_order_id = ?";
46 $listOrders = sqlStatement($sql, array($oid,$encounter,$oid));
48 while ($rows = sqlFetchArray($listOrders)) {
49 $orders[] = $rows['procedure_order_id'];
50 $orders[] = $rows['procedure_order_seq'];
51 $orders[] = $rows['procedure_code'];
52 $orders[] = $rows['procedure_name'];
53 $orders[] = $rows['diagnoses'];
54 $orders[] = $rows['provider_id'];
55 $orders[] = $rows['date_collected'];
56 $orders[] = $rows['lab_id']; //procedure_order.ppid
57 $orders[] = $rows['clinical_hx'];
58 $orders[] = $rows['date_ordered'];
59 $orders[] = $rows['patient_instructions'];
60 $orders[] = $rows['specimen_type'];
61 $orders[] = $rows['specimen_location'];
62 $orders[] = $rows['specimen_volume'];
73 function getSelfPay($pid)
75 $sql = "SELECT subscriber_relationship FROM insurance_data WHERE pid = ?";
76 $res = sqlQuery($sql, array($pid));
78 return $res['subscriber_relationship'];
85 function getNPI($prov_id)
87 $sql = "SELECT npi, upin FROM users WHERE id = ?";
88 $res = sqlQuery($sql, array($prov_id));
89 return array($res['npi'], $res['upin']);
95 function getProcedureProvider($prov_id)
97 $sql = "SELECT i.organization, i.street, i.city, i.state, i.zip, i.fax, i.phone, pi.lab_director " .
98 "FROM users AS i, procedure_providers AS pi WHERE pi.ppid = ? AND pi.lab_director = i.id ";
100 $res = sqlStatement($sql, array($prov_id));
101 $labs = sqlFetchArray($res);
110 function getLabProviders($prov_id)
113 $sql = "select fname, lname from users where authorized = 1 and active = 1 and username != '' and id = ?";
114 $rez = sqlQuery($sql, array($prov_id));
121 * This is going to be adjusted when there is more than one provider.
123 function getLabconfig()
125 $sql = "SELECT recv_app_id, recv_fac_id FROM procedure_providers ";
126 $res = sqlQuery($sql);
130 function saveBarCode($bar, $pid, $order)
132 $sql = "INSERT INTO `requisition` (`id`, `req_id`, `pid`, `lab_id`) VALUES (NULL, ?, ?, ?)";
133 $inarr = array($bar,$pid,$order);
134 sqlStatement($sql, $inarr);
137 function getBarId($lab_id, $pid)
139 $sql = "SELECT req_id FROM requisition WHERE lab_id = ? AND pid = ?";
140 $bar = sqlQuery($sql, array($lab_id,$pid));
147 * @param <type> $facilityID
148 * @return <type> the result set, false if the input is malformed
150 function getFacilityInfo($facilityID)
152 // 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.
153 $facility = explode("_", $facilityID);
155 if (count($facility) > 1) {
156 $query = "SELECT title, fname, lname, street, city, state, zip, organization, phone FROM users WHERE id = ?";
158 $res = sqlStatement($query, array($facility[1]));
159 return sqlFetchArray($res);
165 function formatPhone($phone)
167 $phone = preg_replace("/[^0-9]/", "", $phone);
168 if (strlen($phone) == 7) {
169 return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
170 } elseif (strlen($phone) == 10) {
171 return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);