Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / interface / orders / lab_exchange_match.php
blob1325020c69eb706bb76c0b48085b929428958291
1 <?php
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 ";
16 $where = "";
17 /*
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);
22 if ($res['pid']) {
23 return $res['pid'];
25 else {
26 $where = "";
31 // If empty $externalId or externalId no matched
32 if ($firstName != "")
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)."' " ;
45 if ($dob != ""){
46 if ($where != "") $where .= "AND ";
47 $where .= "DOB = DATE_FORMAT('".add_escape_custom($dob)."', '%Y-%m-%d') " ;
50 if ($gender != "") {
51 if ($gender =="F") $sex = "Female";
52 if ($gender =="M") $sex = "Male";
53 if ($where != "") $where .= "AND ";
54 $where .= "sex = '".add_escape_custom($sex)."' " ;
57 if ($ssn != ""){
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 = '')";
64 if ($where == "") {
65 return false;
67 else {
68 $res = sqlQuery($sql . $where);
69 if ($res['pid']) {
70 return $res['pid'];
72 else {
73 return false;
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 ";
82 $where = "";
84 if ($lastName != "")
85 $where .= "lname = '".add_escape_custom($lastName)."' " ;
87 if ($lastName != "") {
88 if ($where != "") $where .= "AND ";
89 $where .= "fname = '".add_escape_custom($firstName)."' " ;
92 if ($where == "") {
93 return false;
95 else {
96 $res = sqlQuery($sql . $where);
97 if ($res['id']) {
98 return $res['id'];
100 else {
101 return false;
106 function mapReportStatus($stat) {
107 $return_status = $stat;
109 // if($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;
126 // if($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;
145 // if($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";
155 if($stat=="<")
156 $return_status = "low";
157 if($stat==">")
158 $return_status = "high";
159 if($stat=="A" || $stat=="a")
160 $return_status = "yes";
162 return $return_status;