2 include_once("{$GLOBALS['srcdir']}/sql.inc");
3 require_once(dirname(__FILE__) . "/classes/WSWrapper.class.php");
5 function getPatientData($pid, $given = "*, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS") {
6 $sql = "select $given from patient_data where pid='$pid' order by date DESC limit 0,1";
10 function getLanguages() {
11 $returnval = array('','english');
12 $sql = "select distinct lower(language) as language from patient_data";
13 $rez = sqlStatement($sql);
14 for($iter=0; $row=sqlFetchArray($rez); $iter++) {
15 if (($row["language"] != "english") && ($row["language"] != "")) {
16 array_push($returnval, $row["language"]);
24 function getInsuranceProviders() {
28 $sql = "select name, id from insurance_companies order by name, id";
29 $rez = sqlStatement($sql);
30 for($iter=0; $row=sqlFetchArray($rez); $iter++) {
31 $returnval[$row['id']] = $row['name'];
35 // Please leave this here. I have a user who wants to see zip codes and PO
36 // box numbers listed along with the insurance company names, as many companies
37 // have different billing addresses for different plans. -- Rod Roark
40 $sql = "select insurance_companies.name, insurance_companies.id, " .
41 "addresses.zip, addresses.line1 " .
42 "from insurance_companies, addresses " .
43 "where addresses.foreign_id = insurance_companies.id " .
44 "order by insurance_companies.name, addresses.zip";
46 $rez = sqlStatement($sql);
48 for($iter=0; $row=sqlFetchArray($rez); $iter++) {
49 preg_match("/\d+/", $row['line1'], $matches);
50 $returnval[$row['id']] = $row['name'] . " (" . $row['zip'] .
51 "," . $matches[0] . ")";
61 function getProviders() {
62 $returnval = array("");
63 $sql = "select fname,lname from users where authorized=1";
64 $rez = sqlStatement($sql);
65 for($iter=0; $row=sqlFetchArray($rez); $iter++) {
66 if (($row["fname"] != "") && ($row["lname"] != "")) {
67 array_push($returnval, $row["fname"] . " " . $row["lname"]);
75 function getProviderInfo($providerID = "%", $providers_only = true) {
77 if ($providers_only) {
78 $param1 = "AND authorized=1";
81 if ($providerID == "%") {
84 $query = "select distinct id,username,lname,fname, authorized, info, facility from users where id $command '" . mysql_real_escape_string($providerID) . "' " . $param1;
85 $rez = sqlStatement($query);
86 for($iter=0; $row=sqlFetchArray($rez); $iter++)
87 $returnval[$iter]=$row;
89 //if only one result returned take the key/value pairs in array [0] and merge them down the the base array so that $resultval[0]['key'] is also
90 //accessible from $resultval['key']
93 $akeys = array_keys($returnval[0]);
94 foreach($akeys as $key) {
96 $returnval[0][$key] = $returnval[0][$key];
102 //same as above but does not reduce if only 1 row returned
103 function getCalendarProviderInfo($providerID = "%", $providers_only = true) {
105 if ($providers_only) {
106 $param1 = "AND authorized=1";
109 if ($providerID == "%") {
112 $query = "select distinct id,username,lname,fname, authorized, info, facility from users where id $command '" . mysql_real_escape_string($providerID) . "' " . $param1;
114 $rez = sqlStatement($query);
115 for($iter=0; $row=sqlFetchArray($rez); $iter++)
116 $returnval[$iter]=$row;
123 function getProviderName($providerID) {
125 $pi = getProviderInfo($providerID);
127 if (strlen($pi[0]["lname"]) > 0) {
128 return $pi[0]['fname'] . " " . $pi[0]['lname'];
134 function getProviderId($providerName) {
135 $query = "select id from users where username = '". mysql_real_escape_string($providerName)."'";
137 $rez = sqlStatement($query);
138 for($iter=0; $row=sqlFetchArray($rez); $iter++)
139 $returnval[$iter]=$row;
144 function getEthnoRacials() {
145 $returnval = array("");
146 $sql = "select distinct lower(ethnoracial) as ethnoracial from patient_data";
147 $rez = sqlStatement($sql);
148 for($iter=0; $row=sqlFetchArray($rez); $iter++) {
149 if (($row["ethnoracial"] != "")) {
150 array_push($returnval, $row["ethnoracial"]);
158 function getHistoryData($pid, $given = "*")
160 $sql = "select $given from history_data where pid='$pid' order by date DESC limit 0,1";
161 return sqlQuery($sql);
164 // function getInsuranceData($pid, $type = "primary", $given = "insd.*, DATE_FORMAT(subscriber_DOB,'%m/%d/%Y') as subscriber_DOB, ic.name as provider_name")
165 function getInsuranceData($pid, $type = "primary", $given = "insd.*, ic.name as provider_name")
167 $sql = "select $given from insurance_data as insd left join insurance_companies as ic on ic.id = insd.provider where pid='$pid' and type='$type' order by date DESC limit 0,1";
168 return sqlQuery($sql);
171 function getInsuranceDataByDate( $pid, $date, $type, $given = "insd.*, DATE_FORMAT(subscriber_DOB,'%m/%d/%Y') as subscriber_DOB, ic.name as provider_name")
172 { //this must take the date in the following manner: YYYY-MM-DD
173 //this function recalls the insurance value that was most recently enterred from the
174 //given date. it will call up most recent records up to and on the date given,
175 //but not records enterred after the given date
176 $sql = "select $given from insurance_data as insd left join insurance_companies as ic on ic.id = provider where pid='$pid' and date_format(date,'%Y-%m-%d')<='$date' and type='$type' order by date DESC limit 0,1";
177 return sqlQuery($sql);
181 function getEmployerData($pid, $given = "*")
183 $sql = "select $given from employer_data where pid='$pid' order by date DESC limit 0,1";
184 return sqlQuery($sql);
187 function getPatientLnames($lname = "%", $given = "pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS", $orderby = "lname ASC, fname ASC", $limit="all", $start="0")
190 $sql="select pid, MAX(id) as id from patient_data group by pid DESC order by pid ASC";
191 $res = sqlStatement($sql);
192 $sql="select $given from patient_data where lname like '$lname%' and (";
193 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
194 $sql.=" id='{$row['id']}' or";
196 $sql = substr($sql, 0, -3) . ") order by $orderby";
198 $sql = substr($sql, 0, -5)."order by $orderby";
201 // WTF? That was a good way to create a 200KB sql statement.
203 // Allow the last name to be followed by a comma and some part of a first name.
204 // New behavior for searches:
205 // Allows comma alone followed by some part of a first name
206 // If the first letter of either name is capital, searches for name starting
207 // with given substring (the expected behavior). If it is lower case, it
208 // it searches for the substring anywhere in the name. This applies to either
209 // last name or first name or both. The arbitrary limit of 100 results is set
210 // in the sql query below. --Mark Leeds
211 $lname = trim($lname);
213 if (preg_match('/^(.*),(.*)/', $lname, $matches)) {
214 $lname = trim($matches[1]);
215 $fname = trim($matches[2]);
217 $search_for_pieces1 = '';
218 $search_for_pieces2 = '';
219 if ($lname{0} != strtoupper($lname{0})) {$search_for_pieces1 = '%';}
220 if ($fname{0} != strtoupper($fname{0})) {$search_for_pieces2 = '%';}
221 $sql="select $given from patient_data where lname like '"
222 .$search_for_pieces1."$lname%' "
224 .$search_for_pieces2."$fname%' "
225 ."order by $orderby limit 100";
228 $sql .= " limit $start, $limit";
229 $rez = sqlStatement($sql);
231 for($iter=0; $row=sqlFetchArray($rez); $iter++)
232 $returnval[$iter]=$row;
237 function getPatientId($pid = "%", $given = "pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS", $orderby = "lname ASC, fname ASC", $limit="all", $start="0")
240 $sql="select pid, MAX(id) as id from patient_data group by pid DESC order by pid ASC";
241 $res = sqlStatement($sql);
242 $sql="select $given from patient_data where pubpid like '$pid%' and (";
243 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
244 $sql.=" id='{$row['id']}' or";
246 $sql = substr($sql, 0, -3) . ") order by $orderby";
248 $sql = substr($sql, 0, -5)."order by $orderby";
251 $sql = "select $given from patient_data where pubpid like '$pid%' " .
255 $sql .= " limit $start, $limit";
256 $rez = sqlStatement($sql);
257 for($iter=0; $row=sqlFetchArray($rez); $iter++)
258 $returnval[$iter]=$row;
263 function getPatientPID($pid = "%", $given = "pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS", $orderby = "lname ASC, fname ASC", $limit="all", $start="0")
271 if (strstr($pid,"%"))
274 $sql="select $given from patient_data where pid $command '$pid' order by $orderby";
277 $sql .= " limit $start, $limit";
279 $rez = sqlStatement($sql);
280 for($iter=0; $row=sqlFetchArray($rez); $iter++)
281 $returnval[$iter]=$row;
287 function getPatientName($pid) {
290 $patientData = getPatientPID($pid);
291 if (empty($patientData[0]['lname']))
293 $patientName = $patientData[0]['lname'] . ", " . $patientData[0]['fname'];
298 function getPatientDOB($DOB = "%", $given = "pid, id, lname, fname, mname", $orderby = "lname ASC, fname ASC", $limit="all", $start="0")
301 $sql="select pid, MAX(id) as id from patient_data group by pid DESC order by pid ASC";
302 $res = sqlStatement($sql);
303 $sql="select $given from patient_data where DOB like '$DOB%' and (";
304 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
305 $sql.=" id='{$row['id']}' or";
307 $sql = substr($sql, 0, -3) . ") order by $orderby";
309 $sql = substr($sql, 0, -5)."order by $orderby";
312 $DOB = fixDate($DOB, $DOB);
314 $sql="select $given from patient_data where DOB like '$DOB%' " .
318 $sql .= " limit $start, $limit";
320 $rez = sqlStatement($sql);
321 for($iter=0; $row=sqlFetchArray($rez); $iter++)
322 $returnval[$iter]=$row;
327 function getPatientSSN($ss = "%", $given = "pid, id, lname, fname, mname, providerID", $orderby = "lname ASC, fname ASC", $limit="all", $start="0")
330 $sql="select pid, MAX(id) as id from patient_data group by pid DESC order by pid ASC";
331 $res = sqlStatement($sql);
332 $sql="select $given from patient_data where ss like '$ss%' and (";
333 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
334 $sql.=" id='{$row['id']}' or";
336 $sql = substr($sql, 0, -3) . ") order by $orderby";
338 $sql = substr($sql, 0, -5)."order by $orderby";
341 $sql="select $given from patient_data where ss like '$ss%' " .
345 $sql .= " limit $start, $limit";
347 $rez = sqlStatement($sql);
348 for($iter=0; $row=sqlFetchArray($rez); $iter++)
349 $returnval[$iter]=$row;
354 function getPatientIds($given = "pid, id, lname, fname, mname", $orderby = "id ASC", $limit="all", $start="0")
357 $sql="select pid, MAX(id) as id from patient_data group by pid DESC order by pid ASC";
358 $res = sqlStatement($sql);
359 $sql="select $given from patient_data where ";
360 for ($iter = 0;$row = sqlFetchArray($res);$iter++)
361 $sql.="id='{$row['id']}' or ";
362 $sql = substr($sql, 0, -3) . "order by $orderby";
365 $sql="select $given from patient_data order by $orderby";
368 $sql .= " limit $start, $limit";
370 $rez = sqlStatement($sql);
371 for($iter=0; $row=sqlFetchArray($rez); $iter++)
372 $returnval[$iter]=$row;
377 //----------------------input functions
378 function newPatientData( $db_id="",
396 $contact_relationship = "",
403 $migrantseasonal = "",
405 $monthly_income = "",
407 $financial_review = "",
420 $drivers_license = ""
423 $DOB = fixDate($DOB);
427 $rez = sqlQuery("select id, fitness from patient_data where pid = $pid");
428 // Check for brain damage:
429 if ($db_id != $rez['id']) {
430 $errmsg = "Internal error: Attempt to change patient_data.id from '" .
431 $rez['id'] . "' to '$db_id' for pid '$pid'";
434 $fitness = $rez['fitness'];
437 $query = ("replace into patient_data set
446 postal_code='$postal_code',
449 country_code='$country_code',
450 drivers_license='$drivers_license',
452 occupation='$occupation',
453 phone_home='$phone_home',
454 phone_biz='$phone_biz',
455 phone_contact='$phone_contact',
457 contact_relationship='$contact_relationship',
458 referrer='$referrer',
459 referrerID='$referrerID',
461 language='$language',
462 ethnoracial='$ethnoracial',
463 interpretter='$interpretter',
464 migrantseasonal='$migrantseasonal',
465 family_size='$family_size',
466 monthly_income='$monthly_income',
467 homeless='$homeless',
468 financial_review='$financial_review',
471 providerID = '$providerID',
472 genericname1 = '$genericname1',
473 genericval1 = '$genericval1',
474 genericname2 = '$genericname2',
475 genericval2 = '$genericval2',
476 phone_cell = '$phone_cell',
477 pharmacy_id = '$pharmacy_id',
478 hipaa_mail = '$hipaa_mail',
479 hipaa_voice = '$hipaa_voice',
485 $id = sqlInsert($query);
486 $foo = sqlQuery("select pid from patient_data where id='$id' order by date limit 0,1");
488 sync_patient($id,$fname,$lname,$street,$city,$postal_code,$state,$phone_home,
489 $phone_biz,$email,$pid);
494 // Supported input date formats are:
496 // mm/dd/yy (assumes 20yy for yy < 10, else 19yy)
498 // also mm-dd-yyyy, etc. and mm.dd.yyyy, etc.
500 function fixDate($date, $default="0000-00-00") {
501 $fixed_date = $default;
503 if (preg_match("'^[0-9]{1,4}[/.-][0-9]{1,2}[/.-][0-9]{1,4}$'", $date)) {
504 $dmy = preg_split("'[/.-]'", $date);
506 $fixed_date = sprintf("%04u-%02u-%02u", $dmy[0], $dmy[1], $dmy[2]);
508 if ($dmy[2] < 1000) $dmy[2] += 1900;
509 if ($dmy[2] < 1910) $dmy[2] += 100;
510 $fixed_date = sprintf("%04u-%02u-%02u", $dmy[2], $dmy[0], $dmy[1]);
518 function updatePatientData($pid,$new)
520 $real = getPatientData($pid);
521 $new['DOB'] = fixDate($new['DOB']);
522 while(list($key, $value) = each ($new))
523 $real[$key] = $value;
524 $real['date'] = "'+NOW()+'";
527 $sql = "insert into patient_data set ";
528 while(list($key, $value) = each($real))
529 $sql .= $key." = '$value', ";
530 $sql = substr($sql, 0, -2);
533 return sqlInsert($sql);
537 function newEmployerData( $pid,
546 return sqlInsert("insert into employer_data set
549 postal_code='$postal_code',
558 function updateEmployerData($pid,$new)
560 $real = getEmployerData($pid);
561 while(list($key, $value) = each ($new))
562 $real[$key] = $value;
563 $real['date'] = "'+NOW()+'";
566 $sql = "insert into employer_data set ";
567 while(list($key, $value) = each($real))
568 $sql .= $key." = '$value', ";
569 $sql = substr($sql, 0, -2);
572 return sqlInsert($sql);
575 function newInsuranceData( $pid,
581 $subscriber_lname = "",
582 $subscriber_mname = "",
583 $subscriber_fname = "",
584 $subscriber_relationship = "",
586 $subscriber_DOB = "",
587 $subscriber_street = "",
588 $subscriber_postal_code = "",
589 $subscriber_city = "",
590 $subscriber_state = "",
591 $subscriber_country = "",
592 $subscriber_phone = "",
593 $subscriber_employer = "",
594 $subscriber_employer_street = "",
595 $subscriber_employer_city = "",
596 $subscriber_employer_postal_code = "",
597 $subscriber_employer_state = "",
598 $subscriber_employer_country = "",
603 if (strlen($type) > 0) {
604 $query = "select * from insurance_data where type='" . $type . "' and pid = " . $pid . " limit 1";
609 $res = sqlQuery ($query);
612 $data['type'] = $type;
613 $data['provider'] = $provider;
614 $data['policy_number']=$policy_number;
615 $data['group_number']=$group_number;
616 $data['plan_name']=$plan_name;
617 $data['subscriber_lname']=$subscriber_lname;
618 $data['subscriber_mname']=$subscriber_mname;
619 $data['subscriber_fname']=$subscriber_fname;
620 $data['subscriber_relationship']=$subscriber_relationship;
621 $data['subscriber_ss']=$subscriber_ss;
622 $data['subscriber_DOB']=$subscriber_DOB;
623 $data['subscriber_street']=$subscriber_street;
624 $data['subscriber_postal_code']=$subscriber_postal_code;
625 $data['subscriber_city']=$subscriber_city;
626 $data['subscriber_state']=$subscriber_state;
627 $data['subscriber_country']=$subscriber_country;
628 $data['subscriber_phone']=$subscriber_phone;
629 $data['subscriber_employer']=$subscriber_employer;
630 $data['subscriber_employer_city']=$subscriber_employer_city;
631 $data['subscriber_employer_street']=$subscriber_employer_street;
632 $data['subscriber_employer_postal_code']=$subscriber_employer_postal_code;
633 $data['subscriber_employer_state']=$subscriber_employer_state;
634 $data['subscriber_employer_country']=$subscriber_employer_country;
635 $data['copay']=$copay;
636 $data['subscriber_sex']=$subscriber_sex;
638 $data['date']="NOW()";
639 // echo "updating<br><br>";
641 return updateInsuranceData($pid,$data);
644 return sqlInsert("insert into insurance_data set
646 provider='$provider',
647 policy_number='$policy_number',
648 group_number='$group_number',
649 plan_name='$plan_name',
650 subscriber_lname='$subscriber_lname',
651 subscriber_mname='$subscriber_mname',
652 subscriber_fname='$subscriber_fname',
653 subscriber_relationship='$subscriber_relationship',
654 subscriber_ss='$subscriber_ss',
655 subscriber_DOB='$subscriber_DOB',
656 subscriber_street='$subscriber_street',
657 subscriber_postal_code='$subscriber_postal_code',
658 subscriber_city='$subscriber_city',
659 subscriber_state='$subscriber_state',
660 subscriber_country='$subscriber_country',
661 subscriber_phone='$subscriber_phone',
662 subscriber_employer = '$subscriber_employer',
663 subscriber_employer_city='$subscriber_employer_city',
664 subscriber_employer_street='$subscriber_employer_street',
665 subscriber_employer_postal_code='$subscriber_employer_postal_code',
666 subscriber_employer_state='$subscriber_employer_state',
667 subscriber_employer_country='$subscriber_employer_country',
669 subscriber_sex='$subscriber_sex',
676 function updateInsuranceData($pid,$new)
678 $fields = sqlListFields("insurance_data");
680 $real = getInsuranceData($pid);
682 while(list($key, $value) = each ($new)) {
683 if (in_array($key,$fields)){
687 $real['date'] = "'+NOW()+'";
690 $sql = "replace into insurance_data set ";
691 while(list($key, $value) = each($use))
692 $sql .= $key." = '$value', ";
695 $sql = substr($sql, 0, -2);
699 return sqlInsert($sql);
703 function newHistoryData( $pid,
707 $sleep_patterns = "",
708 $exercise_patterns = "",
711 $hazardous_activities = "",
712 $last_breast_exam = "",
713 $last_mammogram = "",
714 $last_gynocological_exam = "",
715 $last_rectal_exam = "",
716 $last_prostate_exam = "",
717 $last_physical_exam = "",
718 $last_sigmoidoscopy_colonoscopy = "",
719 $history_mother = "",
720 $history_father = "",
721 $history_siblings = "",
722 $history_offspring = "",
723 $history_spouse = "",
724 $relatives_cancer = "",
725 $relatives_tuberculosis = "",
726 $relatives_diabetes = "",
727 $relatives_high_blood_pressure = "",
728 $relatives_heart_problems = "",
729 $relatives_stroke = "",
730 $relatives_epilepsy = "",
731 $relatives_mental_illness = "",
732 $relatives_suicide = "",
733 $cataract_surgery = "",
736 $cholecystestomy = "",
740 $hip_replacement = "",
741 $knee_replacement = "",
746 $additional_history = "",
748 $last_cardiac_echo = "",
749 $last_exam_results = ""
752 return sqlInsert("insert into history_data set
756 sleep_patterns='$sleep_patterns',
757 exercise_patterns='$exercise_patterns',
758 seatbelt_use='$seatbelt_use',
759 counseling='$counseling',
760 hazardous_activities='$hazardous_activities',
761 last_breast_exam='$last_breast_exam',
762 last_mammogram='$last_mammogram',
763 last_gynocological_exam='$last_gynocological_exam',
764 last_rectal_exam='$last_rectal_exam',
765 last_prostate_exam='$last_prostate_exam',
766 last_physical_exam='$last_physical_exam',
767 last_sigmoidoscopy_colonoscopy='$last_sigmoidoscopy_colonoscopy',
768 last_ecg='$last_ecg',
769 last_cardiac_echo='$last_cardiac_echo',
770 last_exam_results='$last_exam_results',
771 history_mother='$history_mother',
772 history_father='$history_father',
773 history_siblings='$history_siblings',
774 history_offspring='$history_offspring',
775 history_spouse='$history_spouse',
776 relatives_cancer='$relatives_cancer',
777 relatives_tuberculosis ='$relatives_tuberculosis',
778 relatives_diabetes='$relatives_diabetes',
779 relatives_high_blood_pressure='$relatives_high_blood_pressure',
780 relatives_heart_problems='$relatives_heart_problems',
781 relatives_stroke='$relatives_stroke',
782 relatives_epilepsy='$relatives_epilepsy',
783 relatives_mental_illness='$relatives_mental_illness',
784 relatives_suicide='$relatives_suicide',
785 cataract_surgery='$cataract_surgery',
786 tonsillectomy='$tonsillectomy',
787 appendectomy='$appendectomy',
788 cholecystestomy='$cholecystestomy',
789 heart_surgery='$heart_surgery',
790 hysterectomy='$hysterectomy',
791 hernia_repair='$hernia_repair',
792 hip_replacement='$hip_replacement',
793 knee_replacement='$knee_replacement',
795 value_1 = '$value_1',
797 value_2 = '$value_2',
798 additional_history = '$additional_history',
804 function updateHistoryData($pid,$new)
806 $real = getHistoryData($pid);
807 while(list($key, $value) = each ($new))
808 $real[$key] = $value;
809 $real['date'] = "'+NOW()+'";
812 $sql = "insert into history_data set ";
813 while(list($key, $value) = each($real))
814 $sql .= $key." = '$value', ";
815 $sql = substr($sql, 0, -2);
818 return sqlInsert($sql);
821 function sync_patient($id,$fname,$lname,$street,$city,$postal_code,$state,$phone_home,
822 $phone_biz,$email,$pid="")
824 $db = $GLOBALS['adodb']['db'];
825 $customer_info = array();
827 $sql = "SELECT foreign_id,foreign_table FROM integration_mapping where local_table = 'patient_data' and local_id = '" . $id . "'";
828 $result = $db->Execute($sql);
829 if ($result && !$result->EOF) {
830 $customer_info['foreign_update'] = true;
831 $customer_info['foreign_id'] = $result->fields['foreign_id'];
832 $customer_info['foreign_table'] = $result->fields['foreign_table'];
835 ///xml rpc code to connect to accounting package and add user to it
836 $customer_info['firstname'] = $fname;
837 $customer_info['lastname'] = $lname;
838 $customer_info['address'] = $street;
839 $customer_info['suburb'] = $city;
840 $customer_info['state'] = $state;
841 $customer_info['postcode'] = $postal_code;
843 //ezybiz wants state as a code rather than abbreviation
844 $customer_info['geo_zone_id'] = "";
845 $sql = "SELECT zone_id from geo_zone_reference where zone_code = '" . strtoupper($state) . "'";
846 $db = $GLOBALS['adodb']['db'];
847 $result = $db->Execute($sql);
848 if ($result && !$result->EOF) {
849 $customer_info['geo_zone_id'] = $result->fields['zone_id'];
852 //ezybiz wants country as a code rather than abbreviation
853 $customer_info['geo_country_id'] = "";
854 $sql = "SELECT countries_id from geo_country_reference where countries_iso_code_2 = '" . strtoupper($country_code) . "'";
855 $db = $GLOBALS['adodb']['db'];
856 $result = $db->Execute($sql);
857 if ($result && !$result->EOF) {
858 $customer_info['geo_country_id'] = $result->fields['countries_id'];
862 $customer_info['phone1'] = $phone_home;
863 $customer_info['phone1comment'] = "Home Phone";
864 $customer_info['phone2'] = $phone_biz;
865 $customer_info['phone2comment'] = "Business Phone";
866 $customer_info['email'] = $email;
867 $customer_info['customernumber'] = $pid;
869 $function['ezybiz.add_customer'] = array(new xmlrpcval($customer_info,"struct"));
870 $ws = new WSWrapper($function);
872 // if the remote patient was added make an entry in the local mapping table to that updates can be made correctly
873 if (is_numeric($ws->value)) {
874 $sql = "REPLACE INTO integration_mapping set id = '" . $db->GenID("sequences") . "', foreign_id ='" . $ws->value . "', foreign_table ='customer', local_id = '" . $id . "', local_table = 'patient_data' ";
875 $db->Execute($sql) or die ("error: " . $db->ErrorMsg());
879 // Returns Date of Birth given YYYYMMDD from MySQL DATE_FORMAT(DOB,'%Y%m%d')
880 function getPatientAge($dobYMD)
883 $yearDiff = substr($tdyYMD,0,4) - substr($dobYMD,0,4);
884 $ageInMonths = ((substr($tdyYMD,0,4)*12)+substr($tdyYMD,4,2)) -
885 ((substr($dobYMD,0,4)*12)+substr($dobYMD,4,2));
886 $dayDiff = substr($tdyYMD,6,2) - substr($dobYMD,6,2);
887 if ( $dayDiff < 0 ) {
890 if ( $ageInMonths > 24 ) {
891 $age = intval($ageInMonths/12);
894 $age = "$ageInMonths month";
899 function dateToDB ($date)
901 $date=substr ($date,6,4)."-".substr ($date,3,2)."-".substr($date, 0,2);
908 function DBToDate ($date)
910 $date=substr ($date,5,2)."/".substr ($date,8,2)."/".substr($date, 0,4);