2 // Copyright (C) 2010 OpenEMR Support LLC
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 require_once("../globals.php");
9 require_once("$srcdir/sql.inc");
10 require_once("$srcdir/formdata.inc.php");
12 // Find and match the patient with the incoming lab report.
13 // return patient pid if matched else return false
14 function lab_exchange_match_patient($externalId, $firstName, $middleName, $lastName, $dob, $gender, $ssn, $address) {
15 $sql = "SELECT pid from patient_data WHERE ";
18 // Search for pid and return if pid match with $externalId(from lab API)
19 if ($externalId != "") {
20 $where .= "pid = '".add_escape_custom($externalId)."' " ;
21 $res = sqlQuery($sql . $where);
31 // If empty $externalId or externalId no matched
33 $where .= "fname = '".add_escape_custom($firstName)."' " ;
35 if ($lastName != "") {
36 if ($where != "") $where .= "AND ";
37 $where .= "lname = '".add_escape_custom($lastName)."' " ;
40 if ($middleName != ""){
41 if ($where != "") $where .= "AND ";
42 $where .= "mname = '".add_escape_custom($middleName)."' " ;
46 if ($where != "") $where .= "AND ";
47 $where .= "DOB = DATE_FORMAT('".add_escape_custom($dob)."', '%Y-%m-%d') " ;
51 if ($gender =="F") $sex = "Female";
52 if ($gender =="M") $sex = "Male";
53 if ($where != "") $where .= "AND ";
54 $where .= "sex = '".add_escape_custom($sex)."' " ;
58 if ($where != "") $where .= "AND ";
59 // Change to xxx-xx-xxxx format.
60 $ss = substr($ssn,0,3)."-".substr($ssn,3,2)."-".substr($ssn,5);
61 $where .= "(ss = '".add_escape_custom($ssn)."' OR ss = '".add_escape_custom($ss)."' OR ss = '')";
68 $res = sqlQuery($sql . $where);
78 // Find and match the providers for access to the incoming lab report.
79 // return: - provider/user id or - false
80 function lab_exchange_match_provider($lastName, $firstName) {
81 $sql = "SELECT id from users WHERE ";
85 $where .= "lname = '".add_escape_custom($lastName)."' " ;
87 if ($lastName != "") {
88 if ($where != "") $where .= "AND ";
89 $where .= "fname = '".add_escape_custom($firstName)."' " ;
96 $res = sqlQuery($sql . $where);
106 function mapReportStatus($stat) {
107 $return_status = $stat;
110 // $return_status = "unknown";
111 if($stat=="F" ||
$stat=="f")
112 $return_status = "final";
113 if($stat=="P" ||
$stat=="p")
114 $return_status = "prelim";
115 if($stat=="X" ||
$stat=="x")
116 $return_status = "cancel";
117 if($stat=="C" ||
$stat=="c")
118 $return_status = "correct";
120 return $return_status;
123 function mapResultStatus($stat) {
124 $return_status = $stat;
127 // $return_status = "unknown";
128 if($stat=="F" ||
$stat=="f")
129 $return_status = "final";
130 if($stat=="P" ||
$stat=="p")
131 $return_status = "prelim";
132 if($stat=="X" ||
$stat=="x")
133 $return_status = "cancel";
134 if($stat=="C" ||
$stat=="c")
135 $return_status = "correct";
136 if($stat=="I" ||
$stat=="i")
137 $return_status = "incomplete";
139 return $return_status;
142 function mapAbnormalStatus($stat) {
143 $return_status = $stat;
146 // $return_status = "unknown";
147 if($stat=="L" ||
$stat=="l")
148 $return_status = "low";
149 if($stat=="H" ||
$stat=="h")
150 $return_status = "high";
151 if($stat=="LL" ||
$stat=="ll")
152 $return_status = "low";
153 if($stat=="HH" ||
$stat=="hh")
154 $return_status = "high";
156 $return_status = "low";
158 $return_status = "high";
159 if($stat=="A" ||
$stat=="a")
160 $return_status = "yes";
162 return $return_status;