示例#1
0
 public static function batch_despatch($var, $func, $data_credentials)
 {
     global $pid;
     if (UserService::valid($data_credentials)) {
         require_once "../../library/invoice_summary.inc.php";
         require_once "../../library/options.inc.php";
         require_once "../../library/acl.inc";
         require_once "../../library/patient.inc";
         if ($func == 'ar_responsible_party') {
             $patient_id = $pid;
             $encounter_id = $var['encounter'];
             $x['ar_responsible_party'] = ar_responsible_party($patient_id, $encounter_id);
             return UserService::function_return_to_xml($x);
         } elseif ($func == 'getInsuranceData') {
             $type = $var['type'];
             $given = $var['given'];
             $x = getInsuranceData($pid, $type, $given);
             return UserService::function_return_to_xml($x);
         } elseif ($func == 'generate_select_list') {
             $tag_name = $var['tag_name'];
             $list_id = $var['list_id'];
             $currvalue = $var['currvalue'];
             $title = $var['title'];
             $empty_name = $var['empty_name'];
             $class = $var['class'];
             $onchange = $var['onchange'];
             $x['generate_select_list'] = generate_select_list($tag_name, $list_id, $currvalue, $title, $empty_name, $class, $onchange);
             return UserService::function_return_to_xml($x);
         } elseif ($func == 'xl_layout_label') {
             $constant = $var['constant'];
             $x['xl_layout_label'] = xl_layout_label($constant);
             return UserService::function_return_to_xml($x);
         } elseif ($func == 'generate_form_field') {
             $frow = $var['frow'];
             $currvalue = $var['currvalue'];
             ob_start();
             generate_form_field($frow, $currvalue);
             $x['generate_form_field'] = ob_get_contents();
             ob_end_clean();
             return UserService::function_return_to_xml($x);
         } elseif ($func == 'getInsuranceProviders') {
             $i = $var['i'];
             $provider = $var['provider'];
             $insurancei = getInsuranceProviders();
             $x = $insurancei;
             return $x;
         } elseif ($func == 'get_layout_form_value') {
             $frow = $var['frow'];
             $_POST = $var['post_array'];
             $x['get_layout_form_value'] = get_layout_form_value($frow);
             return UserService::function_return_to_xml($x);
         } elseif ($func == 'updatePatientData') {
             $patient_data = $var['patient_data'];
             $create = $var['create'];
             updatePatientData($pid, $patient_data, $create);
             $x['ok'] = 'ok';
             return UserService::function_return_to_xml($x);
         } elseif ($func == 'updateEmployerData') {
             $employer_data = $var['employer_data'];
             $create = $var['create'];
             updateEmployerData($pid, $employer_data, $create);
             $x['ok'] = 'ok';
             return UserService::function_return_to_xml($x);
         } elseif ($func == 'newHistoryData') {
             newHistoryData($pid);
             $x['ok'] = 'ok';
             return UserService::function_return_to_xml($x);
         } elseif ($func == 'newInsuranceData') {
             $_POST = $var[0];
             foreach ($var as $key => $value) {
                 if ($key >= 3) {
                     $var[$key] = formData($value);
                 }
                 if ($key >= 1) {
                     $parameters[$key] = $var[$key];
                 }
             }
             $parameters[12] = fixDate($parameters[12]);
             $parameters[27] = fixDate($parameters[27]);
             call_user_func_array('newInsuranceData', $parameters);
             $x['ok'] = 'ok';
             return UserService::function_return_to_xml($x);
         } elseif ($func == 'generate_layout_validation') {
             $form_id = $var['form_id'];
             ob_start();
             generate_layout_validation($form_id);
             $x = ob_get_clean();
             return $x;
         }
     } else {
         throw new SoapFault("Server", "credentials failed");
     }
 }
示例#2
0
            $newdata[$table][$field_id] = get_layout_form_value($frow);
        }
    }
    if (empty($ptid)) {
        $tmp = sqlQuery("SELECT MAX(pid)+1 AS pid FROM patient_data");
        $ptid = empty($tmp['pid']) ? 1 : intval($tmp['pid']);
        if (empty($newdata['patient_data']['pubpid'])) {
            // pubpid for new patient defaults to pid.
            $newdata['patient_data']['pubpid'] = "{$ptid}";
        }
        updatePatientData($ptid, $newdata['patient_data'], true);
        updateEmployerData($ptid, $newdata['employer_data'], true);
        newHistoryData($ptid);
    } else {
        $newdata['patient_data']['id'] = $_POST['db_id'];
        updatePatientData($ptid, $newdata['patient_data']);
    }
    // Finally, delete the request from the portal.
    $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
    if ($result['errmsg']) {
        die(text($result['errmsg']));
    }
    echo "<html><body><script language='JavaScript'>\n";
    echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
    echo "document.location.href = 'list_requests.php';\n";
    echo "</script></body></html>\n";
    exit;
}
$db_id = 0;
if ($ptid) {
    $ptrow = getPatientData($ptid, "*");
示例#3
0
 public function update_audited_data($var)
 {
     $data_credentials = $var[0];
     $validtables = array("patient_data", "employer_data", "insurance_data", "history_data", "openemr_postcalendar_events");
     if (UserService::valid($data_credentials)) {
         $audit_master_id = $var['audit_master_id'];
         $res = sqlStatement("SELECT * FROM  audit_master  where id=? and  approval_status='1' and  type='3' ", array($audit_master_id));
         if (sqlNumRows($res) > 0) {
             return;
         }
         $res = sqlStatement("SELECT DISTINCT ad.table_name,am.id,am.pid FROM audit_master as am,audit_details as ad WHERE am.id=ad.audit_master_id and am.approval_status in ('1','4') and am.id=?", array($audit_master_id));
         $tablecnt = sqlNumRows($res);
         while ($row = sqlFetchArray($res)) {
             $pid = $row['pid'];
             $resfield = sqlStatement("SELECT * FROM audit_details WHERE audit_master_id=? AND table_name=?", array($audit_master_id, $row['table_name']));
             $table = $row['table_name'];
             $cnt = 0;
             foreach ($validtables as $value) {
                 //Update will execute if and only if all tables are validtables
                 if ($value == $table) {
                     $cnt++;
                 }
             }
             if ($cnt > 0) {
                 while ($rowfield = sqlFetchArray($resfield)) {
                     if ($table == 'patient_data') {
                         $newdata['patient_data'][$rowfield['field_name']] = $rowfield['field_value'];
                     }
                     if ($table == 'employer_data') {
                         $newdata['employer_data'][$rowfield['field_name']] = $rowfield['field_value'];
                     }
                     if ($table == 'insurance_data') {
                         $ins1_type = "primary";
                         $ins2_type = "secondary";
                         $ins3_type = "tertiary";
                         for ($i = 1; $i <= 3; $i++) {
                             $newdata[$rowfield['entry_identification']][$rowfield['field_name']] = $rowfield['field_value'];
                         }
                     }
                     if ($table == 'openemr_postcalendar_events') {
                         $newdata['openemr_postcalendar_events'][$rowfield['field_name']] = $rowfield['field_value'];
                     }
                 }
                 require_once "../../library/invoice_summary.inc.php";
                 require_once "../../library/options.inc.php";
                 require_once "../../library/acl.inc";
                 require_once "../../library/patient.inc";
                 if ($table == 'patient_data') {
                     $pdrow = sqlQuery("SELECT id from patient_data WHERE pid=?", array($pid));
                     $newdata['patient_data']['id'] = $pdrow['id'];
                     updatePatientData($pid, $newdata['patient_data']);
                 } elseif ($table == 'employer_data') {
                     updateEmployerData($pid, $newdata['employer_data']);
                 } elseif ($table == 'insurance_data') {
                     for ($i = 1; $i <= 3; $i++) {
                         newInsuranceData($pid, add_escape_custom($newdata[${ins . $i . _type}]['type']), add_escape_custom($newdata[${ins . $i . _type}]['provider']), add_escape_custom($newdata[${ins . $i . _type}]['policy_number']), add_escape_custom($newdata[${ins . $i . _type}]['group_number']), add_escape_custom($newdata[${ins . $i . _type}]['plan_name']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_lname']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_mname']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_fname']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_relationship']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_ss']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_DOB']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_street']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_postal_code']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_city']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_state']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_country']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_phone']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer_street']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer_city']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer_postal_code']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer_state']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer_country']), add_escape_custom($newdata[${ins . $i . _type}]['copay']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_sex']), add_escape_custom($newdata[${ins . $i . _type}]['date']), add_escape_custom($newdata[${ins . $i . _type}]['accept_assignment']));
                     }
                 } elseif ($table == 'openemr_postcalendar_events') {
                     sqlInsert("INSERT INTO openemr_postcalendar_events ( " . "pc_pid,pc_title,pc_time,pc_hometext,pc_eventDate,pc_endDate,pc_startTime,pc_endTime,pc_duration,pc_catid,pc_eventstatus,pc_aid,pc_facility" . ") VALUES ( " . "'" . add_escape_custom($pid) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_title']) . "', " . "NOW(), " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_hometext']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_eventDate']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_endDate']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_startTime']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_endTime']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_duration']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_catid']) . "', " . "1, " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_aid']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_facility']) . "')");
                 }
             } else {
                 throw new SoapFault("Server", "Table Not Supported error message");
             }
         }
     } else {
         throw new SoapFault("Server", "credentials failed");
     }
 }
示例#4
0
$s_plan_name = $_POST['s_plan_name'];
$s_subscriber_relationship = $_POST['s_subscriber_relationship'];
$s_insurance_id = $_POST['s_insurance_id'];
$o_insurance_company = $_POST['o_provider'];
$o_subscriber_employer_status = $_POST['o_subscriber_employer'];
$o_group_number = $_POST['o_group_number'];
$o_plan_name = $_POST['o_plan_name'];
$o_subscriber_relationship = $_POST['o_subscriber_relationship'];
$o_insurance_id = $_POST['o_insurance_id'];
$image_data = isset($_POST['image_data']) ? $_POST['image_data'] : '';
if ($userId = validateToken($token)) {
    $user = getUsername($userId);
    $acl_allow = acl_check('patients', 'demo', $user);
    if ($acl_allow) {
        $postData = array('id' => $id, 'title' => $title, 'fname' => $firstname, 'lname' => $lastname, 'mname' => $middlename, 'sex' => $sex, 'status' => $status, 'drivers_license' => $drivers_lincense, 'contact_relationship' => $contact_relationship, 'phone_biz' => $phone_biz, 'phone_cell' => $phone_cell, 'phone_contact' => $phone_contact, 'phone_home' => $phone_home, 'DOB' => $dob, 'language' => $language, 'financial' => $financial, 'street' => $street, 'postal_code' => $postal_code, 'city' => $city, 'state' => $state, 'country_code' => $country_code, 'ss' => $ss, 'occupation' => $occupation, 'email' => $email, 'race' => $race, 'ethnicity' => $ethnicity, 'usertext1' => $usertext1, 'genericname1' => $nickname, 'mothersname' => $mothersname, 'guardiansname' => $guardiansname);
        updatePatientData($patientId, $postData, $create = false);
        $primary_insurace_data = getInsuranceData($patientId);
        $secondary_insurace_data = getInsuranceData($patientId, 'secondary');
        $other_insurace_data = getInsuranceData($patientId, 'tertiary');
        $p_insurace_data = array('provider' => $p_insurance_company, 'group_number' => $p_group_number, 'plan_name' => $p_plan_name, 'subscriber_employer' => $p_subscriber_employer_status, 'subscriber_relationship' => $p_subscriber_relationship, 'policy_number' => $p_insurance_id);
        if ($primary_insurace_data) {
            updateInsuranceData($primary_insurace_data['id'], $p_insurace_data);
        } else {
            newInsuranceData($patientId, $type = "primary", $p_insurance_company, $policy_number = $p_insurance_id, $group_number = $p_group_number, $plan_name = $p_plan_name, $subscriber_lname = "", $subscriber_mname = "", $subscriber_fname = "", $subscriber_relationship = $p_subscriber_relationship, $subscriber_ss = "", $subscriber_DOB = "", $subscriber_street = "", $subscriber_postal_code = "", $subscriber_city = "", $subscriber_state = "", $subscriber_country = "", $subscriber_phone = "", $subscriber_employer = $p_subscriber_employer_status, $subscriber_employer_street = "", $subscriber_employer_city = "", $subscriber_employer_postal_code = "", $subscriber_employer_state = "", $subscriber_employer_country = "", $copay = "", $subscriber_sex = "", $effective_date = "0000-00-00", $accept_assignment = "TRUE");
        }
        $s_insurace_data = array('provider' => $s_insurance_company, 'group_number' => $s_group_number, 'plan_name' => $s_plan_name, 'subscriber_employer' => $s_subscriber_employer_status, 'subscriber_relationship' => $s_subscriber_relationship, 'policy_number' => $s_insurance_id);
        if ($secondary_insurace_data) {
            updateInsuranceData($secondary_insurace_data['id'], $s_insurace_data);
        } else {
            newInsuranceData($patientId, $type = "secondary", $s_insurance_company, $policy_number = $s_insurance_id, $group_number = $s_group_number, $plan_name = $s_plan_name, $subscriber_lname = "", $subscriber_mname = "", $subscriber_fname = "", $subscriber_relationship = $s_subscriber_relationship, $subscriber_ss = "", $subscriber_DOB = "", $subscriber_street = "", $subscriber_postal_code = "", $subscriber_city = "", $subscriber_state = "", $subscriber_country = "", $subscriber_phone = "", $subscriber_employer = $s_subscriber_employer_status, $subscriber_employer_street = "", $subscriber_employer_city = "", $subscriber_employer_postal_code = "", $subscriber_employer_state = "", $subscriber_employer_country = "", $copay = "", $subscriber_sex = "", $effective_date = "0000-00-00", $accept_assignment = "TRUE");
        }
/**
 * Create a patient using whatever patient_data attributes are provided.
 */
function create_skeleton_patient($patient_data)
{
    $employer_data = array();
    $tmp = sqlQuery("SELECT MAX(pid)+1 AS pid FROM patient_data");
    $ptid = empty($tmp['pid']) ? 1 : intval($tmp['pid']);
    if (!isset($patient_data['pubpid'])) {
        $patient_data['pubpid'] = $ptid;
    }
    updatePatientData($ptid, $patient_data, true);
    updateEmployerData($ptid, $employer_data, true);
    newHistoryData($ptid);
    return $ptid;
}
    $data_type = $frow['data_type'];
    $field_id = $frow['field_id'];
    // $value     = '';
    $colname = $field_id;
    $tblname = 'patient_data';
    if (strpos($field_id, 'em_') === 0) {
        $colname = substr($field_id, 3);
        $tblname = 'employer_data';
    }
    $value = get_layout_form_value($frow);
    if ($field_id == 'pubpid' && empty($value)) {
        $value = $pid;
    }
    $newdata[$tblname][$colname] = $value;
}
updatePatientData($pid, $newdata['patient_data'], true);
updateEmployerData($pid, $newdata['employer_data'], true);
$i1dob = fixDate(formData("i1subscriber_DOB"));
$i1date = fixDate(formData("i1effective_date"));
// sqlStatement("unlock tables");
// end table lock
newHistoryData($pid);
newInsuranceData($pid, "primary", formData("i1provider"), formData("i1policy_number"), formData("i1group_number"), formData("i1plan_name"), formData("i1subscriber_lname"), formData("i1subscriber_mname"), formData("i1subscriber_fname"), formData("form_i1subscriber_relationship"), formData("i1subscriber_ss"), $i1dob, formData("i1subscriber_street"), formData("i1subscriber_postal_code"), formData("i1subscriber_city"), formData("form_i1subscriber_state"), formData("form_i1subscriber_country"), formData("i1subscriber_phone"), formData("i1subscriber_employer"), formData("i1subscriber_employer_street"), formData("i1subscriber_employer_city"), formData("i1subscriber_employer_postal_code"), formData("form_i1subscriber_employer_state"), formData("form_i1subscriber_employer_country"), formData('i1copay'), formData('form_i1subscriber_sex'), $i1date, formData('i1accept_assignment'));
$i2dob = fixDate(formData("i2subscriber_DOB"));
$i2date = fixDate(formData("i2effective_date"));
newInsuranceData($pid, "secondary", formData("i2provider"), formData("i2policy_number"), formData("i2group_number"), formData("i2plan_name"), formData("i2subscriber_lname"), formData("i2subscriber_mname"), formData("i2subscriber_fname"), formData("form_i2subscriber_relationship"), formData("i2subscriber_ss"), $i2dob, formData("i2subscriber_street"), formData("i2subscriber_postal_code"), formData("i2subscriber_city"), formData("form_i2subscriber_state"), formData("form_i2subscriber_country"), formData("i2subscriber_phone"), formData("i2subscriber_employer"), formData("i2subscriber_employer_street"), formData("i2subscriber_employer_city"), formData("i2subscriber_employer_postal_code"), formData("form_i2subscriber_employer_state"), formData("form_i2subscriber_employer_country"), formData('i2copay'), formData('form_i2subscriber_sex'), $i2date, formData('i2accept_assignment'));
$i3dob = fixDate(formData("i3subscriber_DOB"));
$i3date = fixDate(formData("i3effective_date"));
newInsuranceData($pid, "tertiary", formData("i3provider"), formData("i3policy_number"), formData("i3group_number"), formData("i3plan_name"), formData("i3subscriber_lname"), formData("i3subscriber_mname"), formData("i3subscriber_fname"), formData("form_i3subscriber_relationship"), formData("i3subscriber_ss"), $i3dob, formData("i3subscriber_street"), formData("i3subscriber_postal_code"), formData("i3subscriber_city"), formData("form_i3subscriber_state"), formData("form_i3subscriber_country"), formData("i3subscriber_phone"), formData("i3subscriber_employer"), formData("i3subscriber_employer_street"), formData("i3subscriber_employer_city"), formData("i3subscriber_employer_postal_code"), formData("form_i3subscriber_employer_state"), formData("form_i3subscriber_employer_country"), formData('i3copay'), formData('form_i3subscriber_sex'), $i3date, formData('i3accept_assignment'));
?>
<html>
示例#7
0
 public function insert_patient($audit_master_id)
 {
     $pid = 0;
     $appTable = new ApplicationTable();
     $pres = $appTable->zQuery("SELECT IFNULL(MAX(pid)+1,1) AS pid FROM patient_data", array());
     foreach ($pres as $prow) {
         $pid = $prow['pid'];
     }
     $res = $appTable->zQuery("SELECT DISTINCT ad.table_name,entry_identification FROM audit_master as am,audit_details as ad WHERE am.id=ad.audit_master_id AND am.approval_status = '1' AND am.id=? AND am.type=11 ORDER BY ad.id", array($audit_master_id));
     $tablecnt = $res->count();
     foreach ($res as $row) {
         $resfield = $appTable->zQuery("SELECT * FROM audit_details WHERE audit_master_id=? AND table_name=? AND entry_identification=?", array($audit_master_id, $row['table_name'], $row['entry_identification']));
         $table = $row['table_name'];
         $newdata = array();
         foreach ($resfield as $rowfield) {
             if ($table == 'patient_data') {
                 if ($rowfield['field_name'] == 'DOB') {
                     $newdata['patient_data'][$rowfield['field_name']] = substr($rowfield['field_value'], 0, 10);
                 } else {
                     $newdata['patient_data'][$rowfield['field_name']] = $rowfield['field_value'];
                 }
             } elseif ($table == 'lists1') {
                 $newdata['lists1'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'lists2') {
                 $newdata['lists2'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'prescriptions') {
                 $newdata['prescriptions'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'immunizations') {
                 $newdata['immunizations'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'procedure_result') {
                 $newdata['procedure_result'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'procedure_type') {
                 $newdata['procedure_type'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'misc_address_book') {
                 $newdata['misc_address_book'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'documents') {
                 $newdata['documents'][$rowfield['field_name']] = $rowfield['field_value'];
             }
         }
         if ($table == 'patient_data') {
             updatePatientData($pid, $newdata['patient_data'], true);
         } elseif ($table == 'lists1') {
             $query_insert = "INSERT INTO lists(pid, diagnosis, activity, title, type, date) VALUES (?,?,?,?,?,?)";
             $appTable->zQuery($query_insert, array($pid, $newdata['lists1']['diagnosis'], $newdata['lists1']['activity'], $newdata['lists1']['title'], 'medical_problem', $newdata['lists1']['date']));
         } elseif ($table == 'lists2' && $newdata['lists2']['diagnosis'] != '') {
             $query_insert = "INSERT INTO lists(pid,date,type,title,diagnosis,reaction) VALUES (?,?,?,?,?,?)";
             $appTable->zQuery($query_insert, array($pid, $newdata['lists2']['date'], $newdata['lists2']['type'], $newdata['lists2']['title'], $newdata['lists2']['diagnosis'], $newdata['lists2']['reaction']));
         } elseif ($table == 'prescriptions' && $newdata['prescriptions']['drug'] != '') {
             $query_insert = "INSERT INTO prescriptions(patient_id,date_added,active,drug,size,form,quantity) VALUES (?,?,?,?,?,?,?)";
             $appTable->zQuery($query_insert, array($pid, $newdata['prescriptions']['date_added'], $newdata['prescriptions']['active'], $newdata['prescriptions']['drug'], $newdata['prescriptions']['size'], $newdata['prescriptions']['form'], $newdata['prescriptions']['quantity']));
         } elseif ($table == 'immunizations') {
             $query_insert = "INSERT INTO immunizations(patient_id,administered_date,note) VALUES (?,?,?)";
             $appTable->zQuery($query_insert, array($pid, $newdata['immunizations']['administered_date'], $newdata['immunizations']['note']));
         } elseif ($table == 'documents') {
             $appTable->zQuery("UPDATE documents SET foreign_id = ? WHERE id =? ", array($pid, $newdata['documents']['id']));
         }
     }
     $appTable->zQuery("UPDATE audit_master SET approval_status=2 WHERE id=?", array($audit_master_id));
     $appTable->zQuery("UPDATE documents SET audit_master_approval_status=2 WHERE audit_master_id=?", array($audit_master_id));
 }
 public function insert_patient($audit_master_id, $document_id)
 {
     require_once dirname(__FILE__) . "/../../../../../../../../library/patient.inc";
     $pid = 0;
     $j = 1;
     $k = 1;
     $q = 1;
     $y = 1;
     $a = 1;
     $b = 1;
     $c = 1;
     $d = 1;
     $e = 1;
     $f = 1;
     $g = 1;
     $arr_procedure_res = array();
     $arr_encounter = array();
     $arr_vitals = array();
     $arr_procedures = array();
     $arr_immunization = array();
     $arr_prescriptions = array();
     $arr_allergies = array();
     $arr_med_pblm = array();
     $arr_care_plan = array();
     $arr_functional_cognitive_status = array();
     $arr_referral = array();
     $appTable = new ApplicationTable();
     $pres = $appTable->zQuery("SELECT IFNULL(MAX(pid)+1,1) AS pid \n                                     FROM patient_data");
     foreach ($pres as $prow) {
         $pid = $prow['pid'];
     }
     $res = $appTable->zQuery("SELECT DISTINCT ad.table_name,\n                                            entry_identification \n                                     FROM audit_master as am,audit_details as ad \n                                     WHERE am.id=ad.audit_master_id AND \n                                     am.approval_status = '1' AND \n                                     am.id=? AND am.type=12 \n                                     ORDER BY ad.id", array($audit_master_id));
     $tablecnt = $res->count();
     foreach ($res as $row) {
         $resfield = $appTable->zQuery("SELECT * \n                                     FROM audit_details \n                                     WHERE audit_master_id=? AND \n                                     table_name=? AND \n                                     entry_identification=?", array($audit_master_id, $row['table_name'], $row['entry_identification']));
         $table = $row['table_name'];
         $newdata = array();
         foreach ($resfield as $rowfield) {
             if ($table == 'patient_data') {
                 if ($rowfield['field_name'] == 'DOB') {
                     $dob = $this->formatDate($rowfield['field_value'], 1);
                     $newdata['patient_data'][$rowfield['field_name']] = $dob;
                 } else {
                     if ($rowfield['field_name'] == 'religion') {
                         $religion_option_id = $this->getOptionId('religious_affiliation', $rowfield['field_value'], '');
                         $newdata['patient_data'][$rowfield['field_name']] = $religion_option_id;
                     } elseif ($rowfield['field_name'] == 'race') {
                         $race_option_id = $this->getOptionId('race', $rowfield['field_value'], '');
                         $newdata['patient_data'][$rowfield['field_name']] = $race_option_id;
                     } elseif ($rowfield['field_name'] == 'ethnicity') {
                         $ethnicity_option_id = $this->getOptionId('ethnicity', $rowfield['field_value'], '');
                         $newdata['patient_data'][$rowfield['field_name']] = $ethnicity_option_id;
                     } else {
                         $newdata['patient_data'][$rowfield['field_name']] = $rowfield['field_value'];
                     }
                 }
             } elseif ($table == 'immunization') {
                 $newdata['immunization'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'lists3') {
                 $newdata['lists3'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'lists1') {
                 $newdata['lists1'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'lists2') {
                 $newdata['lists2'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'vital_sign') {
                 $newdata['vital_sign'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'social_history') {
                 $newdata['social_history'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'encounter') {
                 $newdata['encounter'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'procedure_result') {
                 $newdata['procedure_result'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'procedure') {
                 $newdata['procedure'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'care_plan') {
                 $newdata['care_plan'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'functional_cognitive_status') {
                 $newdata['functional_cognitive_status'][$rowfield['field_name']] = $rowfield['field_value'];
             } elseif ($table == 'referral') {
                 $newdata['referral'][$rowfield['field_name']] = $rowfield['field_value'];
             }
         }
         if ($table == 'patient_data') {
             updatePatientData($pid, $newdata['patient_data'], true);
         } elseif ($table == 'immunization') {
             $arr_immunization['immunization'][$a]['extension'] = $newdata['immunization']['extension'];
             $arr_immunization['immunization'][$a]['root'] = $newdata['immunization']['root'];
             $arr_immunization['immunization'][$a]['administered_date'] = $newdata['immunization']['administered_date'];
             $arr_immunization['immunization'][$a]['route_code'] = $newdata['immunization']['route_code'];
             $arr_immunization['immunization'][$a]['route_code_text'] = $newdata['immunization']['route_code_text'];
             $arr_immunization['immunization'][$a]['cvx_code_text'] = $newdata['immunization']['cvx_code_text'];
             $arr_immunization['immunization'][$a]['cvx_code'] = $newdata['immunization']['cvx_code'];
             $arr_immunization['immunization'][$a]['amount_administered'] = $newdata['immunization']['amount_administered'];
             $arr_immunization['immunization'][$a]['amount_administered_unit'] = $newdata['immunization']['amount_administered_unit'];
             $arr_immunization['immunization'][$a]['manufacturer'] = $newdata['immunization']['manufacturer'];
             $arr_immunization['immunization'][$a]['completion_status'] = $newdata['immunization']['completion_status'];
             $arr_immunization['immunization'][$a]['provider_npi'] = $newdata['immunization']['provider_npi'];
             $arr_immunization['immunization'][$a]['provider_name'] = $newdata['immunization']['provider_name'];
             $arr_immunization['immunization'][$a]['provider_address'] = $newdata['immunization']['provider_address'];
             $arr_immunization['immunization'][$a]['provider_city'] = $newdata['immunization']['provider_city'];
             $arr_immunization['immunization'][$a]['provider_state'] = $newdata['immunization']['provider_state'];
             $arr_immunization['immunization'][$a]['provider_postalCode'] = $newdata['immunization']['provider_postalCode'];
             $arr_immunization['immunization'][$a]['provider_country'] = $newdata['immunization']['provider_country'];
             $arr_immunization['immunization'][$a]['provider_telecom'] = $newdata['immunization']['provider_telecom'];
             $arr_immunization['immunization'][$a]['represented_organization'] = $newdata['immunization']['represented_organization'];
             $arr_immunization['immunization'][$a]['represented_organization_tele'] = $newdata['immunization']['represented_organization_tele'];
             $a++;
         } elseif ($table == 'lists3') {
             $arr_prescriptions['lists3'][$b]['extension'] = $newdata['lists3']['extension'];
             $arr_prescriptions['lists3'][$b]['root'] = $newdata['lists3']['root'];
             $arr_prescriptions['lists3'][$b]['begdate'] = $newdata['lists3']['begdate'];
             $arr_prescriptions['lists3'][$b]['enddate'] = $newdata['lists3']['enddate'];
             $arr_prescriptions['lists3'][$b]['route'] = $newdata['lists3']['route'];
             $arr_prescriptions['lists3'][$b]['note'] = $newdata['lists3']['note'];
             $arr_prescriptions['lists3'][$b]['indication'] = $newdata['lists3']['indication'];
             $arr_prescriptions['lists3'][$b]['route_display'] = $newdata['lists3']['route_display'];
             $arr_prescriptions['lists3'][$b]['dose'] = $newdata['lists3']['dose'];
             $arr_prescriptions['lists3'][$b]['dose_unit'] = $newdata['lists3']['dose_unit'];
             $arr_prescriptions['lists3'][$b]['rate'] = $newdata['lists3']['rate'];
             $arr_prescriptions['lists3'][$b]['rate_unit'] = $newdata['lists3']['rate_unit'];
             $arr_prescriptions['lists3'][$b]['drug_code'] = $newdata['lists3']['drug_code'];
             $arr_prescriptions['lists3'][$b]['drug_text'] = $newdata['lists3']['drug_text'];
             $arr_prescriptions['lists3'][$b]['prn'] = $newdata['lists3']['prn'];
             $arr_prescriptions['lists3'][$b]['provider_address'] = $newdata['lists3']['provider_address'];
             $arr_prescriptions['lists3'][$b]['provider_city'] = $newdata['lists3']['provider_city'];
             $arr_prescriptions['lists3'][$b]['provider_country'] = $newdata['lists3']['provider_country'];
             $arr_prescriptions['lists3'][$b]['provider_title'] = $newdata['lists3']['provider_title'];
             $arr_prescriptions['lists3'][$b]['provider_fname'] = $newdata['lists3']['provider_fname'];
             $arr_prescriptions['lists3'][$b]['provider_lname'] = $newdata['lists3']['provider_lname'];
             $arr_prescriptions['lists3'][$b]['provider_postalCode'] = $newdata['lists3']['provider_postalCode'];
             $arr_prescriptions['lists3'][$b]['provider_state'] = $newdata['lists3']['provider_state'];
             $arr_prescriptions['lists3'][$b]['provider_root'] = $newdata['lists3']['provider_root'];
             $b++;
         } elseif ($table == 'lists1' && $newdata['lists1']['list_code'] != 0) {
             $arr_med_pblm['lists1'][$d]['extension'] = $newdata['lists1']['extension'];
             $arr_med_pblm['lists1'][$d]['root'] = $newdata['lists1']['root'];
             $arr_med_pblm['lists1'][$d]['begdate'] = $newdata['lists1']['begdate'];
             $arr_med_pblm['lists1'][$d]['enddate'] = $newdata['lists1']['enddate'];
             $arr_med_pblm['lists1'][$d]['list_code'] = $newdata['lists1']['list_code'];
             $arr_med_pblm['lists1'][$d]['list_code_text'] = $newdata['lists1']['list_code_text'];
             $arr_med_pblm['lists1'][$d]['status'] = $newdata['lists1']['status'];
             $arr_med_pblm['lists1'][$d]['observation_text'] = $newdata['lists1']['observation_text'];
             $arr_med_pblm['lists1'][$d]['observation_code'] = $newdata['lists1']['observation'];
             $d++;
         } elseif ($table == 'lists2' && $newdata['lists2']['list_code'] != 0) {
             $arr_allergies['lists2'][$c]['extension'] = $newdata['lists2']['extension'];
             $arr_allergies['lists2'][$c]['begdate'] = $newdata['lists2']['begdate'];
             $arr_allergies['lists2'][$c]['enddate'] = $newdata['lists2']['enddate'];
             $arr_allergies['lists2'][$c]['list_code'] = $newdata['lists2']['list_code'];
             $arr_allergies['lists2'][$c]['list_code_text'] = $newdata['lists2']['list_code_text'];
             $arr_allergies['lists2'][$c]['severity_al'] = $newdata['lists2']['severity_al'];
             $arr_allergies['lists2'][$c]['status'] = $newdata['lists2']['status'];
             $arr_allergies['lists2'][$c]['reaction'] = $newdata['lists2']['reaction'];
             $arr_allergies['lists2'][$c]['reaction_text'] = $newdata['lists2']['reaction_text'];
             $arr_allergies['lists2'][$c]['codeSystemName'] = $newdata['lists2']['codeSystemName'];
             $arr_allergies['lists2'][$c]['outcome'] = $newdata['lists2']['outcome'];
             $c++;
         } elseif ($table == 'encounter') {
             $arr_encounter['encounter'][$k]['extension'] = $newdata['encounter']['extension'];
             $arr_encounter['encounter'][$k]['root'] = $newdata['encounter']['root'];
             $arr_encounter['encounter'][$k]['date'] = $newdata['encounter']['date'];
             $arr_encounter['encounter'][$k]['provider_npi'] = $newdata['encounter']['provider_npi'];
             $arr_encounter['encounter'][$k]['provider_name'] = $newdata['encounter']['provider_name'];
             $arr_encounter['encounter'][$k]['provider_address'] = $newdata['encounter']['provider_address'];
             $arr_encounter['encounter'][$k]['provider_city'] = $newdata['encounter']['provider_city'];
             $arr_encounter['encounter'][$k]['provider_state'] = $newdata['encounter']['provider_state'];
             $arr_encounter['encounter'][$k]['provider_postalCode'] = $newdata['encounter']['provider_postalCode'];
             $arr_encounter['encounter'][$k]['provider_country'] = $newdata['encounter']['provider_country'];
             $arr_encounter['encounter'][$k]['represented_organization_name'] = $newdata['encounter']['represented_organization_name'];
             $arr_encounter['encounter'][$k]['represented_organization_address'] = $newdata['encounter']['represented_organization_address'];
             $arr_encounter['encounter'][$k]['represented_organization_city'] = $newdata['encounter']['represented_organization_city'];
             $arr_encounter['encounter'][$k]['represented_organization_state'] = $newdata['encounter']['represented_organization_state'];
             $arr_encounter['encounter'][$k]['represented_organization_zip'] = $newdata['encounter']['represented_organization_zip'];
             $arr_encounter['encounter'][$k]['represented_organization_country'] = $newdata['encounter']['represented_organization_country'];
             $arr_encounter['encounter'][$k]['represented_organization_telecom'] = $newdata['encounter']['represented_organization_telecom'];
             $arr_encounter['encounter'][$k]['encounter_diagnosis_date'] = $newdata['encounter']['encounter_diagnosis_date'];
             $arr_encounter['encounter'][$k]['encounter_diagnosis_code'] = $newdata['encounter']['encounter_diagnosis_code'];
             $arr_encounter['encounter'][$k]['encounter_diagnosis_issue'] = $newdata['encounter']['encounter_diagnosis_issue'];
             $k++;
         } elseif ($table == 'vital_sign') {
             $arr_vitals['vitals'][$q]['extension'] = $newdata['vital_sign']['extension'];
             $arr_vitals['vitals'][$q]['date'] = $newdata['vital_sign']['date'];
             $arr_vitals['vitals'][$q]['temperature'] = $newdata['vital_sign']['temperature'];
             $arr_vitals['vitals'][$q]['bpd'] = $newdata['vital_sign']['bpd'];
             $arr_vitals['vitals'][$q]['bps'] = $newdata['vital_sign']['bps'];
             $arr_vitals['vitals'][$q]['head_circ'] = $newdata['vital_sign']['head_circ'];
             $arr_vitals['vitals'][$q]['pulse'] = $newdata['vital_sign']['pulse'];
             $arr_vitals['vitals'][$q]['height'] = $newdata['vital_sign']['height'];
             $arr_vitals['vitals'][$q]['oxygen_saturation'] = $newdata['vital_sign']['oxygen_saturation'];
             $arr_vitals['vitals'][$q]['respiration'] = $newdata['vital_sign']['respiration'];
             $arr_vitals['vitals'][$q]['weight'] = $newdata['vital_sign']['weight'];
             $q++;
         } elseif ($table == 'social_history') {
             $tobacco_status = array('449868002' => 'Current', '8517006' => 'Quit', '266919005' => 'Never');
             $alcohol_status = array('219006' => 'Current', '82581004' => 'Quit', '228274009' => 'Never');
             $alcohol = explode("|", $newdata['social_history']['alcohol']);
             if ($alcohol[2] != 0) {
                 $alcohol_date = $this->formatDate($alcohol[2], 1);
             } else {
                 $alcohol_date = $alcohol[2];
             }
             $alcohol_date_value = fixDate($alcohol_date);
             foreach ($alcohol_status as $key => $value) {
                 if ($alcohol[1] == $key) {
                     $alcohol[1] = strtolower($value) . "alcohol";
                 }
             }
             $alcohol_value = $alcohol[0] . "|" . $alcohol[1] . "|" . $alcohol_date_value;
             $tobacco = explode("|", $newdata['social_history']['smoking']);
             if ($tobacco[2] != 0) {
                 $smoking_date = $this->formatDate($tobacco[2], 1);
             } else {
                 $smoking_date = $tobacco[2];
             }
             $smoking_date_value = fixDate($smoking_date);
             foreach ($tobacco_status as $key => $value2) {
                 if ($tobacco[1] == $key) {
                     $tobacco[1] = strtolower($value2) . "tobacco";
                 }
             }
             $smoking_value = $tobacco[0] . "|" . $tobacco[1] . "|" . $smoking_date_value;
             $query_insert = "INSERT INTO history_data\n                         (\n                          pid,\n                          alcohol,\n                          tobacco,\n                          date\n                         )\n                         VALUES\n                         (\n                          ?,\n                          ?,\n                          ?,\n                          ?\n                         )";
             $appTable->zQuery($query_insert, array($pid, $alcohol_value, $smoking_value, date('Y-m-d H:i:s')));
         } elseif ($table == 'procedure_result') {
             if ($newdata['procedure_result']['date'] != 0) {
                 $proc_date = $this->formatDate($newdata['procedure_result']['date'], 0);
             } else {
                 $proc_date = $newdata['procedure_result']['date'];
             }
             if ($newdata['procedure_result']['results_date'] != 0) {
                 $proc_result_date = $this->formatDate($newdata['procedure_result']['results_date'], 0);
             } else {
                 $proc_result_date = $newdata['procedure_result']['results_date'];
             }
             $arr_procedure_res['procedure_result'][$j]['proc_text'] = $newdata['procedure_result']['proc_text'];
             $arr_procedure_res['procedure_result'][$j]['proc_code'] = $newdata['procedure_result']['proc_code'];
             $arr_procedure_res['procedure_result'][$j]['extension'] = $newdata['procedure_result']['extension'];
             $arr_procedure_res['procedure_result'][$j]['date'] = $proc_date;
             $arr_procedure_res['procedure_result'][$j]['status'] = $newdata['procedure_result']['status'];
             $arr_procedure_res['procedure_result'][$j]['results_text'] = $newdata['procedure_result']['results_text'];
             $arr_procedure_res['procedure_result'][$j]['results_code'] = $newdata['procedure_result']['results_code'];
             $arr_procedure_res['procedure_result'][$j]['results_range'] = $newdata['procedure_result']['results_range'];
             $arr_procedure_res['procedure_result'][$j]['results_value'] = $newdata['procedure_result']['results_value'];
             $arr_procedure_res['procedure_result'][$j]['results_date'] = $proc_result_date;
             $j++;
         } elseif ($table == 'procedure') {
             $arr_procedures['procedure'][$y]['extension'] = $newdata['procedure']['extension'];
             $arr_procedures['procedure'][$y]['root'] = $newdata['procedure']['root'];
             $arr_procedures['procedure'][$y]['codeSystemName'] = $newdata['procedure']['codeSystemName'];
             $arr_procedures['procedure'][$y]['code'] = $newdata['procedure']['code'];
             $arr_procedures['procedure'][$y]['code_text'] = $newdata['procedure']['code_text'];
             $arr_procedures['procedure'][$y]['date'] = $newdata['procedure']['date'];
             $arr_procedures['procedure'][$y]['represented_organization1'] = $newdata['procedure']['represented_organization1'];
             $arr_procedures['procedure'][$y]['represented_organization_address1'] = $newdata['procedure']['represented_organization_address1'];
             $arr_procedures['procedure'][$y]['represented_organization_city1'] = $newdata['procedure']['represented_organization_city1'];
             $arr_procedures['procedure'][$y]['represented_organization_state1'] = $newdata['procedure']['represented_organization_state1'];
             $arr_procedures['procedure'][$y]['represented_organization_postalcode1'] = $newdata['procedure']['represented_organization_postalcode1'];
             $arr_procedures['procedure'][$y]['represented_organization_country1'] = $newdata['procedure']['represented_organization_country1'];
             $arr_procedures['procedure'][$y]['represented_organization_telecom1'] = $newdata['procedure']['represented_organization_telecom1'];
             $arr_procedures['procedure'][$y]['represented_organization2'] = $newdata['procedure']['represented_organization2'];
             $arr_procedures['procedure'][$y]['represented_organization_address2'] = $newdata['procedure']['represented_organization_address2'];
             $arr_procedures['procedure'][$y]['represented_organization_city2'] = $newdata['procedure']['represented_organization_city2'];
             $arr_procedures['procedure'][$y]['represented_organization_state2'] = $newdata['procedure']['represented_organization_state2'];
             $arr_procedures['procedure'][$y]['represented_organization_postalcode2'] = $newdata['procedure']['represented_organization_postalcode2'];
             $arr_procedures['procedure'][$y]['represented_organization_country2'] = $newdata['procedure']['represented_organization_country2'];
             $y++;
         } elseif ($table == 'care_plan') {
             $arr_care_plan['care_plan'][$e]['extension'] = $newdata['care_plan']['extension'];
             $arr_care_plan['care_plan'][$e]['root'] = $newdata['care_plan']['root'];
             $arr_care_plan['care_plan'][$e]['text'] = $newdata['care_plan']['code_text'];
             $arr_care_plan['care_plan'][$e]['code'] = $newdata['care_plan']['code'];
             $arr_care_plan['care_plan'][$e]['description'] = $newdata['care_plan']['description'];
             $e++;
         } elseif ($table == 'functional_cognitive_status') {
             $arr_functional_cognitive_status['functional_cognitive_status'][$f]['extension'] = $newdata['functional_cognitive_status']['extension'];
             $arr_functional_cognitive_status['functional_cognitive_status'][$f]['root'] = $newdata['functional_cognitive_status']['root'];
             $arr_functional_cognitive_status['functional_cognitive_status'][$f]['text'] = $newdata['functional_cognitive_status']['code_text'];
             $arr_functional_cognitive_status['functional_cognitive_status'][$f]['code'] = $newdata['functional_cognitive_status']['code'];
             $arr_functional_cognitive_status['functional_cognitive_status'][$f]['date'] = $newdata['functional_cognitive_status']['date'];
             $arr_functional_cognitive_status['functional_cognitive_status'][$f]['description'] = $newdata['functional_cognitive_status']['description'];
             $f++;
         } elseif ($table == 'referral') {
             $arr_referral['referral'][$g]['body'] = $newdata['referral']['body'];
             $arr_referral['referral'][$g]['root'] = $newdata['referral']['root'];
             $g++;
         }
     }
     $this->InsertImmunization($arr_immunization['immunization'], $pid, 0);
     $this->InsertPrescriptions($arr_prescriptions['lists3'], $pid, 0);
     $this->InsertAllergies($arr_allergies['lists2'], $pid, 0);
     $this->InsertMedicalProblem($arr_med_pblm['lists1'], $pid, 0);
     $this->InsertEncounter($arr_encounter['encounter'], $pid, 0);
     $this->InsertVitals($arr_vitals['vitals'], $pid, 0);
     $lab_results = $this->buildLabArray($arr_procedure_res['procedure_result']);
     $this->InsertProcedures($arr_procedures['procedure'], $pid, 0);
     $this->InsertLabResults($lab_results, $pid);
     $this->InsertCarePlan($arr_care_plan['care_plan'], $pid, 0);
     $this->InsertFunctionalCognitiveStatus($arr_functional_cognitive_status['functional_cognitive_status'], $pid, 0);
     $this->InsertReferrals($arr_referral['referral'], $pid, 0);
     $appTable->zQuery("UPDATE audit_master \n                       SET approval_status=2 \n                       WHERE id=?", array($audit_master_id));
     $appTable->zQuery("UPDATE documents \n                       SET audit_master_approval_status=2 \n                       WHERE audit_master_id=?", array($audit_master_id));
     $appTable->zQuery("UPDATE documents \n                       SET foreign_id = ? \n                       WHERE id =? ", array($pid, $document_id));
 }
示例#9
0
 public function update_audited_data($var)
 {
     $data_credentials = $var[0];
     $last_insert_ids = array();
     $validtables = array("patient_data", "employer_data", "insurance_data", "history_data", "openemr_postcalendar_events", "ar_session", "documents_legal_master", "documents_legal_detail", "patient_access_offsite");
     if (UserService::valid($data_credentials)) {
         $audit_master_id = $var['audit_master_id'];
         $res = sqlStatement("SELECT DISTINCT ad.table_name,am.id,am.pid FROM audit_master as am,audit_details as ad WHERE am.id=ad.audit_master_id and am.approval_status in ('1','4') and am.id=? ORDER BY ad.id", array($audit_master_id));
         $tablecnt = sqlNumRows($res);
         while ($row = sqlFetchArray($res)) {
             if ($row['pid']) {
                 $pid = $row['pid'];
             }
             $resfield = sqlStatement("SELECT * FROM audit_details WHERE audit_master_id=? AND table_name=?", array($audit_master_id, $row['table_name']));
             $table = $row['table_name'];
             $cnt = 0;
             foreach ($validtables as $value) {
                 //Update will execute if and only if all tables are validtables
                 if ($value == $table) {
                     $cnt++;
                 }
             }
             if ($cnt > 0) {
                 while ($rowfield = sqlFetchArray($resfield)) {
                     if ($rowfield['field_name'] == 'pid') {
                         continue;
                     }
                     if ($table == 'patient_data') {
                         $newdata['patient_data'][$rowfield['field_name']] = $rowfield['field_value'];
                     }
                     if ($table == 'employer_data') {
                         $newdata['employer_data'][$rowfield['field_name']] = $rowfield['field_value'];
                     }
                     if ($table == 'insurance_data') {
                         $ins1_type = "primary";
                         $ins2_type = "secondary";
                         $ins3_type = "tertiary";
                         for ($i = 1; $i <= 3; $i++) {
                             $newdata[$rowfield['entry_identification']][$rowfield['field_name']] = $rowfield['field_value'];
                         }
                     }
                     if ($table == 'openemr_postcalendar_events') {
                         $newdata['openemr_postcalendar_events'][$rowfield['field_name']] = $rowfield['field_value'];
                     }
                     if ($table == 'ar_session') {
                         $newdata['ar_session'][$rowfield['field_name']] = $rowfield['field_value'];
                     }
                     if ($table == 'documents_legal_master') {
                         $newdata['documents_legal_master'][$rowfield['field_name']] = $rowfield['field_value'];
                     }
                     if ($table == 'documents_legal_detail') {
                         $newdata['documents_legal_detail'][$rowfield['field_name']] = $rowfield['field_value'];
                     }
                     if ($table == 'patient_access_offsite') {
                         $newdata['patient_access_offsite'][$rowfield['field_name']] = $rowfield['field_value'];
                         if ($rowfield['field_name'] == 'portal_pwd') {
                             $newdata['patient_access_offsite']['pass_id'] = $rowfield['id'];
                         }
                     }
                 }
                 require_once "../../library/invoice_summary.inc.php";
                 require_once "../../library/options.inc.php";
                 require_once "../../library/acl.inc";
                 require_once "../../library/patient.inc";
                 if ($table == 'patient_data') {
                     $pdrow = sqlQuery("SELECT id from patient_data WHERE pid=?", array($pid));
                     if ($pdrow['id']) {
                         $newdata['patient_data']['id'] = $pdrow['id'];
                         updatePatientData($pid, $newdata['patient_data']);
                     } else {
                         $prow = sqlQuery("SELECT IFNULL(MAX(pid)+1,1) AS pid FROM patient_data");
                         $pid = $prow['pid'];
                         $newdata['patient_data']['pubpid'] = $pid;
                         updatePatientData($pid, $newdata['patient_data'], true);
                     }
                 } elseif ($table == 'employer_data') {
                     updateEmployerData($pid, $newdata['employer_data']);
                 } elseif ($table == 'insurance_data') {
                     for ($i = 1; $i <= 3; $i++) {
                         newInsuranceData($pid, add_escape_custom($newdata[${ins . $i . _type}]['type']), add_escape_custom($newdata[${ins . $i . _type}]['provider']), add_escape_custom($newdata[${ins . $i . _type}]['policy_number']), add_escape_custom($newdata[${ins . $i . _type}]['group_number']), add_escape_custom($newdata[${ins . $i . _type}]['plan_name']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_lname']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_mname']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_fname']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_relationship']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_ss']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_DOB']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_street']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_postal_code']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_city']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_state']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_country']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_phone']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer_street']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer_city']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer_postal_code']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer_state']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_employer_country']), add_escape_custom($newdata[${ins . $i . _type}]['copay']), add_escape_custom($newdata[${ins . $i . _type}]['subscriber_sex']), add_escape_custom($newdata[${ins . $i . _type}]['date']), add_escape_custom($newdata[${ins . $i . _type}]['accept_assignment']));
                     }
                 } elseif ($table == 'openemr_postcalendar_events') {
                     sqlInsert("INSERT INTO openemr_postcalendar_events ( " . "pc_pid,pc_title,pc_time,pc_hometext,pc_eventDate,pc_endDate,pc_startTime,pc_endTime,pc_duration,pc_catid,pc_eventstatus,pc_aid,pc_facility" . ") VALUES ( " . "'" . add_escape_custom($pid) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_title']) . "', " . "NOW(), " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_hometext']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_eventDate']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_endDate']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_startTime']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_endTime']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_duration']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_catid']) . "', " . "1, " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_aid']) . "', " . "'" . add_escape_custom($newdata['openemr_postcalendar_events']['pc_facility']) . "')");
                 } elseif ($table == 'ar_session') {
                     sqlInsert("INSERT INTO ar_session ( " . "payer_id, user_id, reference, check_date, pay_total, modified_time, payment_type, description, post_to_date, patient_id, payment_method" . ") VALUES ( " . "'" . add_escape_custom($newdata['ar_session']['payer_id']) . "', " . "'" . add_escape_custom($newdata['ar_session']['user_id']) . "', " . "'" . add_escape_custom($newdata['ar_session']['reference']) . "', " . "NOW(), " . "'" . add_escape_custom($newdata['ar_session']['pay_total']) . "', " . "NOW(), " . "'" . add_escape_custom($newdata['ar_session']['payment_type']) . "', " . "'" . add_escape_custom($newdata['ar_session']['description']) . "', " . "NOW(), " . "'" . add_escape_custom($pid) . "', " . "'" . add_escape_custom($newdata['ar_session']['payment_method']) . "')");
                 } elseif ($table == 'documents_legal_master') {
                     $master_doc_id = sqlInsert("INSERT INTO documents_legal_master ( " . "dlm_category,dlm_subcategory,dlm_document_name,dlm_filepath,dlm_facility,dlm_provider,dlm_sign_height,dlm_sign_width,dlm_filename,dlm_effective_date,dlm_version,content,dlm_savedsign,dlm_review,dlm_upload_type" . ") VALUES ( " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_category']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_subcategory']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_document_name']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_filepath'] . "/{$pid}") . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_facility']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_provider']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_sign_height']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_sign_width']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_filename']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_effective_date']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_version']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['content']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_savedsign']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_review']) . "', " . "'" . add_escape_custom($newdata['documents_legal_master']['dlm_upload_type']) . "')");
                     $last_insert_ids['dlm_id'] = $master_doc_id;
                 } elseif ($table == 'documents_legal_detail') {
                     if ($master_doc_id) {
                         $mdoc_id = $master_doc_id;
                     } else {
                         $mdoc_id = $newdata['documents_legal_detail']['dld_master_docid'];
                     }
                     $last_insert_ids['dld_id'] = sqlInsert("INSERT INTO documents_legal_detail ( " . "dld_pid,dld_facility,dld_provider,dld_encounter,dld_master_docid,dld_signed,dld_signed_time,dld_filepath,dld_filename,dld_signing_person,dld_sign_level,dld_content,dld_file_for_pdf_generation,dld_denial_reason,dld_moved,dld_patient_comments" . ") VALUES ( " . "'" . add_escape_custom($pid) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_facility']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_provider']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_encounter']) . "', " . "'" . add_escape_custom($mdoc_id) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_signed']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_signed_time']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_filepath']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_filename']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_signing_person']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_sign_level']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_content']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_file_for_pdf_generation']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_denial_reason']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_moved']) . "', " . "'" . add_escape_custom($newdata['documents_legal_detail']['dld_patient_comments']) . "')");
                 } elseif ($table == 'patient_access_offsite') {
                     $query = sqlStatement("SELECT * FROM patient_access_offsite WHERE portal_username = '******'patient_access_offsite']['portal_username'] . "'");
                     if (sqlNumRows($query) == 0) {
                         sqlInsert("INSERT INTO patient_access_offsite ( " . "pid,portal_username,portal_pwd,portal_pwd_status" . ") VALUES ( " . "'" . add_escape_custom($pid) . "', " . "'" . add_escape_custom($newdata['patient_access_offsite']['portal_username']) . "', " . "'" . add_escape_custom($newdata['patient_access_offsite']['portal_pwd']) . "', " . "0)");
                         sqlQuery("UPDATE audit_details SET field_value = ? WHERE id = ?", array($this->generatePassword(), $newdata['patient_access_offsite']['pass_id']));
                     }
                 }
             } else {
                 throw new SoapFault("Server", "Table Not Supported error message");
             }
         }
         return $last_insert_ids;
     } else {
         throw new SoapFault("Server", "credentials failed");
     }
 }
示例#10
0
if ($userId = validateToken($token)) {
    $user = getUsername($userId);
    $acl_allow = acl_check('patients', 'demo', $user);
    if ($acl_allow) {
        $provider_id = $userId;
        $patientId = 1;
        $pid = 1;
        sqlStatement("lock tables patient_data read");
        $result = sqlQuery("select max(pid)+1 as pid from patient_data");
        sqlStatement("unlock tables");
        if ($result['pid'] > 1) {
            $patientId = $result['pid'];
            $pid = $result['pid'];
        }
        $postData = array('title' => $title, 'fname' => $firstname, 'lname' => $lastname, 'mname' => $middlename, 'sex' => $sex, 'status' => $status, 'drivers_license' => $drivers_lincense, 'contact_relationship' => $contact_relationship, 'phone_biz' => $phone_biz, 'phone_cell' => $phone_cell, 'phone_contact' => $phone_contact, 'phone_home' => $phone_home, 'DOB' => $dob, 'language' => $language, 'financial' => $financial, 'street' => $street, 'postal_code' => $postal_code, 'city' => $city, 'state' => $state, 'country_code' => $country_code, 'ss' => $ss, 'occupation' => $occupation, 'email' => $email, 'race' => $race, 'ethnicity' => $ethnicity, 'pubpid' => $pid, 'usertext1' => $usertext1, 'genericname1' => $nickname, 'mothersname' => $mothersname, 'guardiansname' => $guardiansname, 'providerID' => $provider_id, 'ref_providerID' => 0, 'financial_review' => '0000-00-00 00:00:00', 'hipaa_allowsms' => '', 'hipaa_allowemail' => '', 'deceased_date' => '0000-00-00 00:0');
        $p_id = updatePatientData($patientId, $postData, $create = true);
        if ($p_id) {
            $primary_insurace_data = getInsuranceData($p_id);
            $secondary_insurace_data = getInsuranceData($p_id, 'secondary');
            $other_insurace_data = getInsuranceData($p_id, 'tertiary');
            $p_insurace_data = array('provider' => $p_insurance_company, 'group_number' => $p_group_number, 'plan_name' => $p_plan_name, 'subscriber_employer' => $p_subscriber_employer_status, 'subscriber_relationship' => $p_subscriber_relationship, 'policy_number' => $p_insurance_id);
            if ($primary_insurace_data) {
                updateInsuranceData($primary_insurace_data['id'], $p_insurace_data);
            } else {
                newInsuranceData($patientId, $type = "primary", $p_insurance_company, $policy_number = $p_insurance_id, $group_number = $p_group_number, $plan_name = $p_plan_name, $subscriber_lname = "", $subscriber_mname = "", $subscriber_fname = "", $subscriber_relationship = $p_subscriber_relationship, $subscriber_ss = "", $subscriber_DOB = "", $subscriber_street = "", $subscriber_postal_code = "", $subscriber_city = "", $subscriber_state = "", $subscriber_country = "", $subscriber_phone = "", $subscriber_employer = $p_subscriber_employer_status, $subscriber_employer_street = "", $subscriber_employer_city = "", $subscriber_employer_postal_code = "", $subscriber_employer_state = "", $subscriber_employer_country = "", $copay = "", $subscriber_sex = "", $effective_date = "0000-00-00", $accept_assignment = "TRUE");
            }
            $s_insurace_data = array('provider' => $s_insurance_company, 'group_number' => $s_group_number, 'plan_name' => $s_plan_name, 'subscriber_employer' => $s_subscriber_employer_status, 'subscriber_relationship' => $s_subscriber_relationship, 'policy_number' => $s_insurance_id);
            if ($secondary_insurace_data) {
                updateInsuranceData($secondary_insurace_data['id'], $s_insurace_data);
            } else {
                newInsuranceData($p_id, $type = "secondary", $s_insurance_company, $policy_number = $s_insurance_id, $group_number = $s_group_number, $plan_name = $s_plan_name, $subscriber_lname = "", $subscriber_mname = "", $subscriber_fname = "", $subscriber_relationship = $s_subscriber_relationship, $subscriber_ss = "", $subscriber_DOB = "", $subscriber_street = "", $subscriber_postal_code = "", $subscriber_city = "", $subscriber_state = "", $subscriber_country = "", $subscriber_phone = "", $subscriber_employer = $s_subscriber_employer_status, $subscriber_employer_street = "", $subscriber_employer_city = "", $subscriber_employer_postal_code = "", $subscriber_employer_state = "", $subscriber_employer_country = "", $copay = "", $subscriber_sex = "", $effective_date = "0000-00-00", $accept_assignment = "TRUE");
示例#11
0
function insert_patient($audit_master_id)
{
    $prow = sqlQuery("SELECT IFNULL(MAX(pid)+1,1) AS pid FROM patient_data");
    $pid = $prow['pid'];
    $res = sqlStatement("SELECT DISTINCT ad.table_name,entry_identification FROM audit_master as am,audit_details as ad WHERE am.id=ad.audit_master_id AND am.approval_status = '1' AND am.id=? AND am.type=11 ORDER BY ad.id", array($audit_master_id));
    $tablecnt = sqlNumRows($res);
    while ($row = sqlFetchArray($res)) {
        $resfield = sqlStatement("SELECT * FROM audit_details WHERE audit_master_id=? AND table_name=? AND entry_identification=?", array($audit_master_id, $row['table_name'], $row['entry_identification']));
        $table = $row['table_name'];
        $newdata = array();
        while ($rowfield = sqlFetchArray($resfield)) {
            if ($table == 'patient_data') {
                if ($rowfield['field_name'] == 'DOB') {
                    $newdata['patient_data'][$rowfield['field_name']] = substr($rowfield['field_value'], 0, 10);
                } else {
                    $newdata['patient_data'][$rowfield['field_name']] = $rowfield['field_value'];
                }
            } elseif ($table == 'lists1') {
                $newdata['lists1'][$rowfield['field_name']] = $rowfield['field_value'];
            } elseif ($table == 'lists2') {
                $newdata['lists2'][$rowfield['field_name']] = $rowfield['field_value'];
            } elseif ($table == 'prescriptions') {
                $newdata['prescriptions'][$rowfield['field_name']] = $rowfield['field_value'];
            } elseif ($table == 'immunizations') {
                $newdata['immunizations'][$rowfield['field_name']] = $rowfield['field_value'];
            } elseif ($table == 'procedure_result') {
                $newdata['procedure_result'][$rowfield['field_name']] = $rowfield['field_value'];
            } elseif ($table == 'procedure_type') {
                $newdata['procedure_type'][$rowfield['field_name']] = $rowfield['field_value'];
            } elseif ($table == 'misc_address_book') {
                $newdata['misc_address_book'][$rowfield['field_name']] = $rowfield['field_value'];
            } elseif ($table == 'documents') {
                $newdata['documents'][$rowfield['field_name']] = $rowfield['field_value'];
            }
        }
        if ($table == 'patient_data') {
            updatePatientData($pid, $newdata['patient_data'], true);
        } elseif ($table == 'lists1') {
            sqlInsert("INSERT INTO lists(" . "pid,diagnosis,activity" . ") VALUES (" . "'" . add_escape_custom($pid) . "'," . "'" . add_escape_custom($newdata['lists1']['diagnosis']) . "'," . "'" . add_escape_custom($newdata['lists1']['activity']) . "')");
        } elseif ($table == 'lists2') {
            sqlInsert("INSERT INTO lists(" . "pid,date,type,title,diagnosis,reaction" . ") VALUES (" . "'" . add_escape_custom($pid) . "'," . "'" . add_escape_custom($newdata['lists2']['date']) . "'," . "'" . add_escape_custom($newdata['lists2']['type']) . "'," . "'" . add_escape_custom($newdata['lists2']['title']) . "'," . "'" . add_escape_custom($newdata['lists2']['diagnosis']) . "'," . "'" . add_escape_custom($newdata['lists2']['reaction']) . "')");
        } elseif ($table == 'prescriptions') {
            sqlInsert("INSERT INTO prescriptions(" . "patient_id,date_added,active,drug,size,form,quantity" . ") VALUES (" . "'" . add_escape_custom($pid) . "'," . "'" . add_escape_custom($newdata['prescriptions']['date_added']) . "'," . "'" . add_escape_custom($newdata['prescriptions']['active']) . "'," . "'" . add_escape_custom($newdata['prescriptions']['drug']) . "'," . "'" . add_escape_custom($newdata['prescriptions']['size']) . "'," . "'" . add_escape_custom($newdata['prescriptions']['form']) . "'," . "'" . add_escape_custom($newdata['prescriptions']['quantity']) . "')");
        } elseif ($table == 'immunizations') {
            sqlInsert("INSERT INTO immunizations(" . "patient_id,administered_date,note" . ") VALUES (" . "'" . add_escape_custom($pid) . "'," . "'" . add_escape_custom($newdata['immunizations']['administered_date']) . "'," . "'" . add_escape_custom($newdata['immunizations']['note']) . "')");
        } elseif ($table == 'procedure_result') {
            /*sqlInsert("INSERT INTO procedure_result(".
            			"date,result,abnormal".
            			") VALUES (".
            			"'".add_escape_custom($newdata['procedure_result']['date'])."',".
            			"'".add_escape_custom($newdata['procedure_result']['result'])."',".
            			"'".add_escape_custom($newdata['procedure_result']['abnormal'])."')"
            		);*/
        } elseif ($table == 'procedure_type') {
            /*sqlInsert("INSERT INTO procedure_type(".
            			"name".
            			") VALUES (".
            			"'".add_escape_custom($newdata['procedure_type']['name'])."')"
            		);*/
        } elseif ($table == 'misc_address_book') {
            sqlInsert("INSERT INTO misc_address_book(" . "lname,fname,street,city,state,zip,phone" . ") VALUES (" . "'" . add_escape_custom($newdata['misc_address_book']['lname']) . "'," . "'" . add_escape_custom($newdata['misc_address_book']['fname']) . "'," . "'" . add_escape_custom($newdata['misc_address_book']['street']) . "'," . "'" . add_escape_custom($newdata['misc_address_book']['city']) . "'," . "'" . add_escape_custom($newdata['misc_address_book']['state']) . "'," . "'" . add_escape_custom($newdata['misc_address_book']['zip']) . "'," . "'" . add_escape_custom($newdata['misc_address_book']['phone']) . "')");
        } elseif ($table == 'documents') {
            sqlQuery("UPDATE documents SET foreign_id = ? WHERE id =? ", array($pid, $newdata['documents']['id']));
        }
    }
    sqlQuery("UPDATE audit_master SET approval_status=2 WHERE id=?", array($audit_master_id));
}