function create_patient(&$medics, &$errors) { $alertmsg = ""; $patient_pid = get_patientid($medics); $pubpid = trim($medics->pubpid); // ID must be valid or 'NEWPATIENT' if (empty($pubpid)) { array_push($errors, "Patient ID '{$pubpid}' missing, patient skipped! "); return $alertmsg; } if ($pubpid != 'NEWPATIENT') { // 1. validate patient $patient_pid = 0; $query = "SELECT pid FROM patient_data WHERE pubpid LIKE '{$pubpid}'"; $res = sqlStatement($query); $row = sqlFetchArray($res); if ($row) { $patient_pid = $row['pid']; if (sqlFetchArray($res)) { array_push($errors, "Patient ID '{$pubpid}' is ambiguous, patient skipped! "); return $alertmsg; } else { // array_push( $errors, "Patient ID '$pubpid' exists, updates/new encounters only. "); } } } // 2. validate insurance provider - REMOVED // 3. validate billing provider $tmp = array(); $tmp = fetchProviderInfo($medics); if (!array($tmp)) { array_push($errors, "Provider '{$tmp}' not found, patient skipped!"); return $alertmsg; } $patient_provider_id = $tmp['id']; $patient_provider_name = $tmp['username']; $patient_provider_facility = $tmp['facility_id']; // 4. get facility from // Move to function $row = sqlQuery("SELECT id, name, pos_code FROM facility WHERE id = '{$patient_provider_facility}'"); if (!$row['id']) { array_push($errors, "Facility '{$tmp}' not found, patient skipped! "); return $alertmsg; } $patient_facility_id = $row['id']; $patient_facility_name = $row['name']; $patient_facility_pos = $row['pos_code']; // 5. insert patient data if (!$patient_pid) { // Insert into patient_data. // $row = sqlQuery("SELECT max(pid)+1 AS pid FROM patient_data"); $patient_pid = $row['pid'] ? $row['pid'] : 1; // Combine street lines $patient_street = $medics->street . ' ' . $medics->street2; // Build array newPatientData('', '', form2db($medics->fname), form2db($medics->lname), form2db($medics->mname), sex($medics->sex), form2db($medics->dob), form2db($patient_street), '', '', '', form2db($medics->zip), form2db($medics->city), form2db($medics->state), '', '', '', form2db($medics->phone_home), form2db($medics->phone_alternate), '', '', '', '', '', '', '', form2db($medics->ethnicity), '', '', '', '', '', '0000-00-00 00:00:00', $patient_pid, $patient_pid, '', '', '', '', '', '', form2db($medics->hippa_notice), form2db($medics->hippa_notice), '', '', '', form2db($medics->hippa_notice), '', $dos = fixDate($medics->fromdate)); // Insert dummy row for employer_data. newEmployerData($patient_pid); // Update or Instest subscriber ins data if ($medics->pubpid == 'NEWPATIENT' || !empty($medics->policy_id)) { newInsuranceData($patient_pid, 'primary', $insurance_company_id, form2db($medics->policy_id), '', '', form2db($medics->lname), form2db($medics->mname), form2db($medics->fname), 'self', '', fixDate($medics->dob), form2db($medics->street), form2db($medics->zip), form2db($medics->city), form2db($medics->state), '', form2db($medics->phone_home), '', '', '', '', '', '', '', sex($medics->sex), fixDate($medics->eff_date)); } $tmp = $medics->lname . ',' . $medics->fname; $alertmsg .= "New Patient Added: '{$patient_pid}' / '{$tmp}' <br>\n"; } $medics->pid = $patient_pid; $history = array('history_father' => form2db($medics->familyinformation->father), 'history_mother' => form2db($medics->familyinformation->mother), 'history_spouse' => form2db($medics->familyinformation->spouse), 'history_siblings' => form2db($medics->familyinformation->siblings), 'history_offspring' => form2db($medics->familyinformation->offspring), 'relatives_cancer' => form2db($medics->medical->relativesexperience->cancer), 'relatives_tuberculosis' => form2db($medics->medical->relativesexperience->tuberculosis), 'relatives_diabetes' => form2db($medics->medical->relativesexperience->diabetes), 'relatives_high_blood_pressure' => form2db($medics->medical->relativesexperience->highbloodpressure), 'relatives_heart_problems' => form2db($medics->medical->relativesexperience->heartproblems), 'relatives_stroke' => form2db($medics->medical->relativesexperience->stroke), 'relatives_epilepsy' => form2db($medics->medical->relativesexperience->epilepsy), 'relatives_mental_illness' => form2db($medics->medical->relativesexperience->mentalillness), 'relatives_suicide' => form2db($medics->medical->relativesexperience->suicide), 'usertext12' => form2db($medics->medical->relativesexperience->other), 'coffee' => form2db($medics->medical->lifestyleusage->coffee), 'tobacco' => form2db($medics->medical->lifestyleusage->tobacco), 'alcohol' => form2db($medics->medical->lifestyleusage->alcohol), 'sleep_patterns' => form2db($medics->medical->lifestyleusage->sleep), 'exercise_patterns' => form2db($medics->medical->lifestyleusage->exercise), 'seatbelt_use' => form2db($medics->medical->lifestyleusage->seatbelt), 'counseling' => form2db($medics->medical->lifestyleusage->counseling), 'hazardous_activities' => form2db($medics->medical->lifestyleusage->hazardactivities), 'usertext13' => form2db($medics->medical->lifestyleusage->urinaryincontinence), 'usertext14' => form2db($medics->medical->lifestyleusage->fallhistory), 'additional_history' => form2db($medics->medical->lifestyleusage->other) . " " . form2db($medics->medical->lifestyleusage->generalnotes)); // Insert/Update into history_data. if ($medics->pubpid == 'NEWPATIENT') { newHistoryData($patient_pid, $history); } else { updateHistoryData($patient_pid, $history); } // Add or Update History data add_update_history($medics, $patient_pid, $errors); // Create or update an issue for each historical medication. // foreach ($medics->medical->medications->medication as $medication) { if (isempty($medication->name)) { continue; } $meds = array(); $meds['title'] = form2db($medication->name); $meds['dosage'] = form2db($medication->dosage); $meds['frequency'] = form2db($medication->frequency); $meds['duration'] = form2db($medication->duration); // TBD does not exsist in MEDICS $meds['id'] = form2db($medication->id); if (!isempty($meds['id'])) { $row = sqlQuery("SELECT id FROM lists WHERE id = " . $meds['id']); if (!$row) { create_issue($patient_pid, 'medication', $meds); } else { update_issue($patient_pid, 'medication', $meds); } } else { create_issue($patient_pid, 'medication', $meds); } } return $alertmsg; }
if ($_POST['form_create']) { $form_fname = ucwords(trim($_POST["fname"])); $form_lname = ucwords(trim($_POST["lname"])); $form_mname = ucwords(trim($_POST["mname"])); // =================== // DBC SYSTEM WAS REMOVED $form_sex = trim($_POST["sex"]); $form_dob = trim($_POST["DOB"]); $form_street = ''; $form_city = ''; $form_postcode = ''; $form_countrycode = ''; // EOS DBC // =================== newPatientData($_POST["db_id"], $_POST["title"], $form_fname, $form_lname, $form_mname, $form_sex, $form_dob, $form_street, $form_postcode, $form_city, "", $form_countrycode, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "{$mypubpid}", $pid, "", "", "", "", "", "", "", "", 0, 0, "", "", "", $_POST['regdate']); newEmployerData($pid); newHistoryData($pid); newInsuranceData($pid, "primary"); newInsuranceData($pid, "secondary"); newInsuranceData($pid, "tertiary"); // Set referral source separately because we don't want it messed // with later by newPatientData(). if ($refsource = trim($_POST["refsource"])) { sqlQuery("UPDATE patient_data SET referral_source = '{$refsource}' " . "WHERE pid = '{$pid}'"); } } ?> <html> <body> <script language="Javascript"> <?php
} } } } } } } else { $alertmsg = "Invalid import data!"; } xml_parser_free($parser); $olddata = getPatientData($pid); if ($olddata['squad'] && !acl_check('squads', $olddata['squad'])) { die("You are not authorized to access this squad."); } newPatientData($olddata['id'], $apatient['title'], $apatient['fname'], $apatient['lname'], $apatient['mname'], $apatient['sex'], $apatient['dob'], $apatient['street'], $apatient['zip'], $apatient['city'], $apatient['state'], $apatient['country'], $apatient['ss'], $apatient['occupation'], $apatient['phone_home'], $apatient['phone_biz'], $apatient['phone_contact'], $apatient['status'], $apatient['contact_relationship'], $apatient['referrer'], $apatient['referrerID'], $apatient['email'], $apatient['language'], $apatient['ethnoracial'], $apatient['interpreter'], $apatient['migrantseasonal'], $apatient['family_size'], $apatient['monthly_income'], $apatient['homeless'], fixDate($apatient['financial_review']), $apatient['pubpid'], $pid, $olddata['providerID'], $apatient['genericname1'], $apatient['genericval1'], $apatient['genericname2'], $apatient['genericval2'], $apatient['phone_cell'], $apatient['hipaa_mail'], $apatient['hipaa_voice'], $olddata['squad']); newEmployerData($pid, $aemployer['name'], $aemployer['street'], $aemployer['zip'], $aemployer['city'], $aemployer['state'], $aemployer['country']); setInsurance($pid, $ainsurance, $asubscriber, '1'); setInsurance($pid, $ainsurance, $asubscriber, '2'); setInsurance($pid, $ainsurance, $asubscriber, '3'); echo "<html>\n<body>\n<script language='JavaScript'>\n"; if ($alertmsg) { echo " alert('{$alertmsg}');\n"; } echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n"; echo " window.close();\n"; echo "</script>\n</body>\n</html>\n"; exit; } ?> <html> <head>