2 include_once("{$GLOBALS['srcdir']}/sql.inc");
3 require_once(dirname(__FILE__) . "/classes/WSWrapper.class.php");
5 // These are for sports team use:
6 $PLAYER_FITNESSES = array(
9 xl('Restricted Training'),
13 xl('International Duty')
15 $PLAYER_FITCOLORS = array('#6677ff', '#00cc00', '#ffff00', '#ff3333', '#ff8800', '#ffeecc', '#ffccaa');
17 function getPatientData($pid, $given = "*, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS") {
18 $sql = "select $given from patient_data where pid='$pid' order by date DESC limit 0,1";
19 return sqlQuery($sql);
22 function getLanguages() {
23 $returnval = array('','english');
24 $sql = "select distinct lower(language) as language from patient_data";
25 $rez = sqlStatement($sql);
26 for($iter=0; $row=sqlFetchArray($rez); $iter++) {
27 if (($row["language"] != "english") && ($row["language"] != "")) {
28 array_push($returnval, $row["language"]);
34 function getInsuranceProviders() {
38 $sql = "select name, id from insurance_companies order by name, id";
39 $rez = sqlStatement($sql);
40 for($iter=0; $row=sqlFetchArray($rez); $iter++) {
41 $returnval[$row['id']] = $row['name'];
45 // Please leave this here. I have a user who wants to see zip codes and PO
46 // box numbers listed along with the insurance company names, as many companies
47 // have different billing addresses for different plans. -- Rod Roark
50 $sql = "select insurance_companies.name, insurance_companies.id, " .
51 "addresses.zip, addresses.line1 " .
52 "from insurance_companies, addresses " .
53 "where addresses.foreign_id = insurance_companies.id " .
54 "order by insurance_companies.name, addresses.zip";
56 $rez = sqlStatement($sql);
58 for($iter=0; $row=sqlFetchArray($rez); $iter++) {
59 preg_match("/\d+/", $row['line1'], $matches);
60 $returnval[$row['id']] = $row['name'] . " (" . $row['zip'] .
61 "," . $matches[0] . ")";
68 function getProviders() {
69 $returnval = array("");
70 $sql = "select fname, lname from users where authorized = 1 and " .
71 "active = 1 and username != ''";
72 $rez = sqlStatement($sql);
73 for($iter=0; $row=sqlFetchArray($rez); $iter++) {
74 if (($row["fname"] != "") && ($row["lname"] != "")) {
75 array_push($returnval, $row["fname"] . " " . $row["lname"]);
81 function getProviderInfo($providerID = "%", $providers_only = true) {
83 if ($providers_only) {
84 $param1 = "AND authorized=1";
87 if ($providerID == "%") {
90 $query = "select distinct id, username, lname, fname, authorized, info, facility " .
91 "from users where username != '' and active = 1 and id $command '" .
92 mysql_real_escape_string($providerID) . "' " . $param1;
93 $rez = sqlStatement($query);
94 for($iter=0; $row=sqlFetchArray($rez); $iter++)
95 $returnval[$iter]=$row;
97 //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
98 //accessible from $resultval['key']
101 $akeys = array_keys($returnval[0]);
102 foreach($akeys as $key) {
104 $returnval[0][$key] = $returnval[0][$key];
110 //same as above but does not reduce if only 1 row returned
111 function getCalendarProviderInfo($providerID = "%", $providers_only = true) {
113 if ($providers_only) {
114 $param1 = "AND authorized=1";
117 if ($providerID == "%") {
120 $query = "select distinct id, username, lname, fname, authorized, info, facility " .
121 "from users where active = 1 and username != '' and id $command '" .
122 mysql_real_escape_string($providerID) . "' " . $param1;
124 $rez = sqlStatement($query);
125 for($iter=0; $row=sqlFetchArray($rez); $iter++)
126 $returnval[$iter]=$row;
131 function getProviderName($providerID) {
132 $pi = getProviderInfo($providerID);
133 if (strlen($pi[0]["lname"]) > 0) {
134 return $pi[0]['fname'] . " " . $pi[0]['lname'];
139 function getProviderId($providerName) {
140 $query = "select id from users where username = '". mysql_real_escape_string($providerName)."'";
141 $rez = sqlStatement($query);
142 for($iter=0; $row=sqlFetchArray($rez); $iter++)
143 $returnval[$iter]=$row;
147 function getEthnoRacials() {
148 $returnval = array("");
149 $sql = "select distinct lower(ethnoracial) as ethnoracial from patient_data";
150 $rez = sqlStatement($sql);
151 for($iter=0; $row=sqlFetchArray($rez); $iter++) {
152 if (($row["ethnoracial"] != "")) {
153 array_push($returnval, $row["ethnoracial"]);
159 function getHistoryData($pid, $given = "*")
161 $sql = "select $given from history_data where pid='$pid' order by date DESC limit 0,1";
162 return sqlQuery($sql);
165 // function getInsuranceData($pid, $type = "primary", $given = "insd.*, DATE_FORMAT(subscriber_DOB,'%m/%d/%Y') as subscriber_DOB, ic.name as provider_name")
166 function getInsuranceData($pid, $type = "primary", $given = "insd.*, ic.name as provider_name")
168 $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";
169 return sqlQuery($sql);
172 function getInsuranceDataByDate( $pid, $date, $type, $given = "insd.*, DATE_FORMAT(subscriber_DOB,'%m/%d/%Y') as subscriber_DOB, ic.name as provider_name")
173 { //this must take the date in the following manner: YYYY-MM-DD
174 //this function recalls the insurance value that was most recently enterred from the
175 //given date. it will call up most recent records up to and on the date given,
176 //but not records enterred after the given date
177 $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";
178 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")
189 // Allow the last name to be followed by a comma and some part of a first name.
190 // New behavior for searches:
191 // Allows comma alone followed by some part of a first name
192 // If the first letter of either name is capital, searches for name starting
193 // with given substring (the expected behavior). If it is lower case, it
194 // it searches for the substring anywhere in the name. This applies to either
195 // last name or first name or both. The arbitrary limit of 100 results is set
196 // in the sql query below. --Mark Leeds
197 $lname = trim($lname);
199 if (preg_match('/^(.*),(.*)/', $lname, $matches)) {
200 $lname = trim($matches[1]);
201 $fname = trim($matches[2]);
203 $search_for_pieces1 = '';
204 $search_for_pieces2 = '';
205 if ($lname{0} != strtoupper($lname{0})) {$search_for_pieces1 = '%';}
206 if ($fname{0} != strtoupper($fname{0})) {$search_for_pieces2 = '%';}
207 $sql="select $given from patient_data where lname like '"
208 .$search_for_pieces1."$lname%' "
210 .$search_for_pieces2."$fname%' "
211 ."order by $orderby limit 100";
214 $sql .= " limit $start, $limit";
215 $rez = sqlStatement($sql);
217 for($iter=0; $row=sqlFetchArray($rez); $iter++)
218 $returnval[$iter]=$row;
223 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")
225 $sql = "select $given from patient_data where pubpid like '$pid%' " .
229 $sql .= " limit $start, $limit";
230 $rez = sqlStatement($sql);
231 for($iter=0; $row=sqlFetchArray($rez); $iter++)
232 $returnval[$iter]=$row;
237 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")
245 if (strstr($pid,"%"))
248 $sql="select $given from patient_data where pid $command '$pid' order by $orderby";
251 $sql .= " limit $start, $limit";
253 $rez = sqlStatement($sql);
254 for($iter=0; $row=sqlFetchArray($rez); $iter++)
255 $returnval[$iter]=$row;
260 function getPatientName($pid) {
263 $patientData = getPatientPID($pid);
264 if (empty($patientData[0]['lname']))
266 $patientName = $patientData[0]['lname'] . ", " . $patientData[0]['fname'];
270 function getPatientDOB($DOB = "%", $given = "pid, id, lname, fname, mname", $orderby = "lname ASC, fname ASC", $limit="all", $start="0")
272 $DOB = fixDate($DOB, $DOB);
274 $sql="select $given from patient_data where DOB like '$DOB%' " .
278 $sql .= " limit $start, $limit";
280 $rez = sqlStatement($sql);
281 for($iter=0; $row=sqlFetchArray($rez); $iter++)
282 $returnval[$iter]=$row;
287 function getPatientSSN($ss = "%", $given = "pid, id, lname, fname, mname, providerID", $orderby = "lname ASC, fname ASC", $limit="all", $start="0")
289 $sql="select $given from patient_data where ss like '$ss%' " .
293 $sql .= " limit $start, $limit";
295 $rez = sqlStatement($sql);
296 for($iter=0; $row=sqlFetchArray($rez); $iter++)
297 $returnval[$iter]=$row;
302 function getPatientIds($given = "pid, id, lname, fname, mname", $orderby = "id ASC", $limit="all", $start="0")
304 $sql="select $given from patient_data order by $orderby";
307 $sql .= " limit $start, $limit";
309 $rez = sqlStatement($sql);
310 for($iter=0; $row=sqlFetchArray($rez); $iter++)
311 $returnval[$iter]=$row;
316 //----------------------input functions
317 function newPatientData( $db_id="",
335 $contact_relationship = "",
342 $migrantseasonal = "",
344 $monthly_income = "",
346 $financial_review = "",
359 $drivers_license = "",
364 $DOB = fixDate($DOB);
367 $referral_source = '';
369 $rez = sqlQuery("select id, fitness, referral_source from patient_data where pid = $pid");
370 // Check for brain damage:
371 if ($db_id != $rez['id']) {
372 $errmsg = "Internal error: Attempt to change patient_data.id from '" .
373 $rez['id'] . "' to '$db_id' for pid '$pid'";
376 $fitness = $rez['fitness'];
377 $referral_source = $rez['referral_source'];
380 $query = ("replace into patient_data set
389 postal_code='$postal_code',
392 country_code='$country_code',
393 drivers_license='$drivers_license',
395 occupation='$occupation',
396 phone_home='$phone_home',
397 phone_biz='$phone_biz',
398 phone_contact='$phone_contact',
400 contact_relationship='$contact_relationship',
401 referrer='$referrer',
402 referrerID='$referrerID',
404 language='$language',
405 ethnoracial='$ethnoracial',
406 interpretter='$interpretter',
407 migrantseasonal='$migrantseasonal',
408 family_size='$family_size',
409 monthly_income='$monthly_income',
410 homeless='$homeless',
411 financial_review='$financial_review',
414 providerID = '$providerID',
415 genericname1 = '$genericname1',
416 genericval1 = '$genericval1',
417 genericname2 = '$genericname2',
418 genericval2 = '$genericval2',
419 phone_cell = '$phone_cell',
420 pharmacy_id = '$pharmacy_id',
421 hipaa_mail = '$hipaa_mail',
422 hipaa_voice = '$hipaa_voice',
423 hipaa_notice = '$hipaa_notice',
424 hipaa_message = '$hipaa_message',
427 referral_source='$referral_source',
431 $id = sqlInsert($query);
432 $foo = sqlQuery("select pid from patient_data where id='$id' order by date limit 0,1");
434 sync_patient($id,$fname,$lname,$street,$city,$postal_code,$state,$phone_home,
435 $phone_biz,$email,$pid);
440 // Supported input date formats are:
442 // mm/dd/yy (assumes 20yy for yy < 10, else 19yy)
444 // also mm-dd-yyyy, etc. and mm.dd.yyyy, etc.
446 function fixDate($date, $default="0000-00-00") {
447 $fixed_date = $default;
449 if (preg_match("'^[0-9]{1,4}[/.-][0-9]{1,2}[/.-][0-9]{1,4}$'", $date)) {
450 $dmy = preg_split("'[/.-]'", $date);
452 $fixed_date = sprintf("%04u-%02u-%02u", $dmy[0], $dmy[1], $dmy[2]);
454 if ($dmy[2] < 1000) $dmy[2] += 1900;
455 if ($dmy[2] < 1910) $dmy[2] += 100;
456 $fixed_date = sprintf("%04u-%02u-%02u", $dmy[2], $dmy[0], $dmy[1]);
463 function updatePatientData($pid,$new)
465 $real = getPatientData($pid);
466 $new['DOB'] = fixDate($new['DOB']);
467 while(list($key, $value) = each ($new))
468 $real[$key] = $value;
469 $real['date'] = "'+NOW()+'";
472 $sql = "insert into patient_data set ";
473 while(list($key, $value) = each($real))
474 $sql .= $key." = '$value', ";
475 $sql = substr($sql, 0, -2);
478 return sqlInsert($sql);
481 function newEmployerData( $pid,
490 return sqlInsert("insert into employer_data set
493 postal_code='$postal_code',
502 function updateEmployerData($pid,$new)
504 $real = getEmployerData($pid);
505 while(list($key, $value) = each ($new))
506 $real[$key] = $value;
507 $real['date'] = "'+NOW()+'";
510 $sql = "insert into employer_data set ";
511 while(list($key, $value) = each($real))
512 $sql .= $key." = '$value', ";
513 $sql = substr($sql, 0, -2);
516 return sqlInsert($sql);
519 function newInsuranceData( $pid,
525 $subscriber_lname = "",
526 $subscriber_mname = "",
527 $subscriber_fname = "",
528 $subscriber_relationship = "",
530 $subscriber_DOB = "",
531 $subscriber_street = "",
532 $subscriber_postal_code = "",
533 $subscriber_city = "",
534 $subscriber_state = "",
535 $subscriber_country = "",
536 $subscriber_phone = "",
537 $subscriber_employer = "",
538 $subscriber_employer_street = "",
539 $subscriber_employer_city = "",
540 $subscriber_employer_postal_code = "",
541 $subscriber_employer_state = "",
542 $subscriber_employer_country = "",
547 if (strlen($type) > 0) {
548 $query = "select * from insurance_data where type='" . $type . "' and pid = " . $pid . " limit 1";
553 $res = sqlQuery ($query);
556 $data['type'] = $type;
557 $data['provider'] = $provider;
558 $data['policy_number']=$policy_number;
559 $data['group_number']=$group_number;
560 $data['plan_name']=$plan_name;
561 $data['subscriber_lname']=$subscriber_lname;
562 $data['subscriber_mname']=$subscriber_mname;
563 $data['subscriber_fname']=$subscriber_fname;
564 $data['subscriber_relationship']=$subscriber_relationship;
565 $data['subscriber_ss']=$subscriber_ss;
566 $data['subscriber_DOB']=$subscriber_DOB;
567 $data['subscriber_street']=$subscriber_street;
568 $data['subscriber_postal_code']=$subscriber_postal_code;
569 $data['subscriber_city']=$subscriber_city;
570 $data['subscriber_state']=$subscriber_state;
571 $data['subscriber_country']=$subscriber_country;
572 $data['subscriber_phone']=$subscriber_phone;
573 $data['subscriber_employer']=$subscriber_employer;
574 $data['subscriber_employer_city']=$subscriber_employer_city;
575 $data['subscriber_employer_street']=$subscriber_employer_street;
576 $data['subscriber_employer_postal_code']=$subscriber_employer_postal_code;
577 $data['subscriber_employer_state']=$subscriber_employer_state;
578 $data['subscriber_employer_country']=$subscriber_employer_country;
579 $data['copay']=$copay;
580 $data['subscriber_sex']=$subscriber_sex;
582 $data['date']="NOW()";
583 // echo "updating<br><br>";
585 return updateInsuranceData($pid,$data);
588 return sqlInsert("insert into insurance_data set
590 provider='$provider',
591 policy_number='$policy_number',
592 group_number='$group_number',
593 plan_name='$plan_name',
594 subscriber_lname='$subscriber_lname',
595 subscriber_mname='$subscriber_mname',
596 subscriber_fname='$subscriber_fname',
597 subscriber_relationship='$subscriber_relationship',
598 subscriber_ss='$subscriber_ss',
599 subscriber_DOB='$subscriber_DOB',
600 subscriber_street='$subscriber_street',
601 subscriber_postal_code='$subscriber_postal_code',
602 subscriber_city='$subscriber_city',
603 subscriber_state='$subscriber_state',
604 subscriber_country='$subscriber_country',
605 subscriber_phone='$subscriber_phone',
606 subscriber_employer = '$subscriber_employer',
607 subscriber_employer_city='$subscriber_employer_city',
608 subscriber_employer_street='$subscriber_employer_street',
609 subscriber_employer_postal_code='$subscriber_employer_postal_code',
610 subscriber_employer_state='$subscriber_employer_state',
611 subscriber_employer_country='$subscriber_employer_country',
613 subscriber_sex='$subscriber_sex',
620 function updateInsuranceData($pid,$new)
622 $fields = sqlListFields("insurance_data");
624 $real = getInsuranceData($pid);
626 while(list($key, $value) = each ($new)) {
627 if (in_array($key,$fields)){
631 $real['date'] = "'+NOW()+'";
634 $sql = "replace into insurance_data set ";
635 while(list($key, $value) = each($use))
636 $sql .= $key." = '$value', ";
639 $sql = substr($sql, 0, -2);
643 return sqlInsert($sql);
647 function newHistoryData( $pid,
651 $sleep_patterns = "",
652 $exercise_patterns = "",
655 $hazardous_activities = "",
656 $last_breast_exam = "",
657 $last_mammogram = "",
658 $last_gynocological_exam = "",
659 $last_rectal_exam = "",
660 $last_prostate_exam = "",
661 $last_physical_exam = "",
662 $last_sigmoidoscopy_colonoscopy = "",
663 $history_mother = "",
664 $history_father = "",
665 $history_siblings = "",
666 $history_offspring = "",
667 $history_spouse = "",
668 $relatives_cancer = "",
669 $relatives_tuberculosis = "",
670 $relatives_diabetes = "",
671 $relatives_high_blood_pressure = "",
672 $relatives_heart_problems = "",
673 $relatives_stroke = "",
674 $relatives_epilepsy = "",
675 $relatives_mental_illness = "",
676 $relatives_suicide = "",
677 $cataract_surgery = "",
680 $cholecystestomy = "",
684 $hip_replacement = "",
685 $knee_replacement = "",
690 $additional_history = "",
692 $last_cardiac_echo = "",
693 $last_exam_results = ""
696 return sqlInsert("insert into history_data set
700 sleep_patterns='$sleep_patterns',
701 exercise_patterns='$exercise_patterns',
702 seatbelt_use='$seatbelt_use',
703 counseling='$counseling',
704 hazardous_activities='$hazardous_activities',
705 last_breast_exam='$last_breast_exam',
706 last_mammogram='$last_mammogram',
707 last_gynocological_exam='$last_gynocological_exam',
708 last_rectal_exam='$last_rectal_exam',
709 last_prostate_exam='$last_prostate_exam',
710 last_physical_exam='$last_physical_exam',
711 last_sigmoidoscopy_colonoscopy='$last_sigmoidoscopy_colonoscopy',
712 last_ecg='$last_ecg',
713 last_cardiac_echo='$last_cardiac_echo',
714 last_exam_results='$last_exam_results',
715 history_mother='$history_mother',
716 history_father='$history_father',
717 history_siblings='$history_siblings',
718 history_offspring='$history_offspring',
719 history_spouse='$history_spouse',
720 relatives_cancer='$relatives_cancer',
721 relatives_tuberculosis ='$relatives_tuberculosis',
722 relatives_diabetes='$relatives_diabetes',
723 relatives_high_blood_pressure='$relatives_high_blood_pressure',
724 relatives_heart_problems='$relatives_heart_problems',
725 relatives_stroke='$relatives_stroke',
726 relatives_epilepsy='$relatives_epilepsy',
727 relatives_mental_illness='$relatives_mental_illness',
728 relatives_suicide='$relatives_suicide',
729 cataract_surgery='$cataract_surgery',
730 tonsillectomy='$tonsillectomy',
731 appendectomy='$appendectomy',
732 cholecystestomy='$cholecystestomy',
733 heart_surgery='$heart_surgery',
734 hysterectomy='$hysterectomy',
735 hernia_repair='$hernia_repair',
736 hip_replacement='$hip_replacement',
737 knee_replacement='$knee_replacement',
739 value_1 = '$value_1',
741 value_2 = '$value_2',
742 additional_history = '$additional_history',
749 function newHistoryData($pid, $new=false) {
750 $sql = "insert into history_data set pid = '$pid', date = NOW()";
752 while(list($key, $value) = each($new)) {
753 if (!get_magic_quotes_gpc()) $value = addslashes($value);
754 $sql .= ", $key = '$value'";
757 return sqlInsert($sql);
760 function updateHistoryData($pid,$new)
762 $real = getHistoryData($pid);
763 while(list($key, $value) = each ($new))
764 $real[$key] = $value;
765 $real['date'] = "'+NOW()+'";
768 $sql = "insert into history_data set ";
769 while(list($key, $value) = each($real))
770 $sql .= $key." = '$value', ";
771 $sql = substr($sql, 0, -2);
774 return sqlInsert($sql);
777 function sync_patient($id,$fname,$lname,$street,$city,$postal_code,$state,$phone_home,
778 $phone_biz,$email,$pid="")
780 $db = $GLOBALS['adodb']['db'];
781 $customer_info = array();
783 $sql = "SELECT foreign_id,foreign_table FROM integration_mapping where local_table = 'patient_data' and local_id = '" . $id . "'";
784 $result = $db->Execute($sql);
785 if ($result && !$result->EOF) {
786 $customer_info['foreign_update'] = true;
787 $customer_info['foreign_id'] = $result->fields['foreign_id'];
788 $customer_info['foreign_table'] = $result->fields['foreign_table'];
791 ///xml rpc code to connect to accounting package and add user to it
792 $customer_info['firstname'] = $fname;
793 $customer_info['lastname'] = $lname;
794 $customer_info['address'] = $street;
795 $customer_info['suburb'] = $city;
796 $customer_info['state'] = $state;
797 $customer_info['postcode'] = $postal_code;
799 //ezybiz wants state as a code rather than abbreviation
800 $customer_info['geo_zone_id'] = "";
801 $sql = "SELECT zone_id from geo_zone_reference where zone_code = '" . strtoupper($state) . "'";
802 $db = $GLOBALS['adodb']['db'];
803 $result = $db->Execute($sql);
804 if ($result && !$result->EOF) {
805 $customer_info['geo_zone_id'] = $result->fields['zone_id'];
808 //ezybiz wants country as a code rather than abbreviation
809 $customer_info['geo_country_id'] = "";
810 $sql = "SELECT countries_id from geo_country_reference where countries_iso_code_2 = '" . strtoupper($country_code) . "'";
811 $db = $GLOBALS['adodb']['db'];
812 $result = $db->Execute($sql);
813 if ($result && !$result->EOF) {
814 $customer_info['geo_country_id'] = $result->fields['countries_id'];
818 $customer_info['phone1'] = $phone_home;
819 $customer_info['phone1comment'] = "Home Phone";
820 $customer_info['phone2'] = $phone_biz;
821 $customer_info['phone2comment'] = "Business Phone";
822 $customer_info['email'] = $email;
823 $customer_info['customernumber'] = $pid;
825 $function['ezybiz.add_customer'] = array(new xmlrpcval($customer_info,"struct"));
826 $ws = new WSWrapper($function);
828 // if the remote patient was added make an entry in the local mapping table to that updates can be made correctly
829 if (is_numeric($ws->value)) {
830 $sql = "REPLACE INTO integration_mapping set id = '" . $db->GenID("sequences") . "', foreign_id ='" . $ws->value . "', foreign_table ='customer', local_id = '" . $id . "', local_table = 'patient_data' ";
831 $db->Execute($sql) or die ("error: " . $db->ErrorMsg());
835 // Returns Date of Birth given YYYYMMDD from MySQL DATE_FORMAT(DOB,'%Y%m%d')
836 function getPatientAge($dobYMD)
839 $yearDiff = substr($tdyYMD,0,4) - substr($dobYMD,0,4);
840 $ageInMonths = ((substr($tdyYMD,0,4)*12)+substr($tdyYMD,4,2)) -
841 ((substr($dobYMD,0,4)*12)+substr($dobYMD,4,2));
842 $dayDiff = substr($tdyYMD,6,2) - substr($dobYMD,6,2);
843 if ( $dayDiff < 0 ) {
846 if ( $ageInMonths > 24 ) {
847 $age = intval($ageInMonths/12);
850 $age = "$ageInMonths month";
855 function dateToDB ($date)
857 $date=substr ($date,6,4)."-".substr ($date,3,2)."-".substr($date, 0,2);
861 function DBToDate ($date)
863 $date=substr ($date,5,2)."/".substr ($date,8,2)."/".substr($date, 0,4);