예제 #1
0
function get_data_array($check_status_sql)
{
    $check_status_query = mysql_query("{$check_status_sql}") or die("Error 57: " . mysql_error());
    if (mysql_num_rows($check_status_query) >= 1) {
        //create an array of all the entry in ehr_lite when m_push_status = 'Y'
        if (!isset($all_array)) {
            $all_array = array();
        } else {
            unset($all_array);
        }
        if (!isset($collect_array)) {
            $collect_array = array();
        } else {
            unset($collect_array);
        }
        while (list($lite_px_id, $emr_px_id, $lite_specific_id, $emr_specific_id, $table_name, $entry_date, $sync_type) = mysql_fetch_array($check_status_query)) {
            //echo $check_status_sql;
            $lite_id = $lite_specific_id;
            //echo "WHY THIS?".$lite_id;
            $data_array = array($lite_px_id, $emr_px_id, $lite_id, $emr_specific_id, $table_name, $entry_date, $sync_type);
            $prime_key_sql = mysql_query("SELECT * FROM {$table_name}") or die("Error 88 :" . mysql_error());
            if ($table_name == 'm_consult_ptgroup') {
                $prime_key = mysql_field_name($prime_key_sql, 1);
            } else {
                $prime_key = mysql_field_name($prime_key_sql, 0);
            }
            $key_count = mysql_num_fields($prime_key_sql) - 1;
            $all_keys = array();
            for ($x = 0; $x <= $key_count; $x++) {
                $keys = mysql_field_name($prime_key_sql, $x);
                array_push($all_keys, $keys);
            }
            if ($table_name == 'm_patient') {
                $get_data_sql = mysql_query("SELECT * FROM {$table_name} WHERE patient_id ='{$lite_px_id}'") or die("Error 93: " . mysql_error());
            } else {
                if (in_array('patient_id', $all_keys)) {
                    if ($table_name == 'm_patient_philhealth') {
                        $get_data_sql = mysql_query("SELECT * FROM {$table_name} WHERE patient_id ='{$lite_px_id}'") or die("Error 95: " . mysql_error());
                        $dup_sql = "SELECT * FROM {$table_name} WHERE patient_id ='{$lite_px_id}'";
                        //echo "ATEST";
                    } elseif ($table_name == 'm_patient_fp_method_service') {
                        $get_data_sql = mysql_query("SELECT * FROM {$table_name} WHERE fp_px_id ='{$lite_specific_id}' AND patient_id ='{$lite_px_id}'") or die("Error 95: " . mysql_error());
                        $dup_sql = "SELECT * FROM {$table_name} WHERE fp_px_id ='{$lite_specific_id}' AND patient_id ='{$lite_px_id}'";
                        //echo "BTEST";
                    } else {
                        $get_data_sql = mysql_query("SELECT * FROM {$table_name} WHERE {$prime_key} ='{$lite_specific_id}' AND patient_id ='{$lite_px_id}'") or die("Error 95: " . mysql_error());
                        $dup_sql = "SELECT * FROM {$table_name} WHERE {$prime_key} ='{$lite_specific_id}' AND patient_id ='{$lite_px_id}'";
                        //echo "CTEST";
                    }
                } else {
                    $get_data_sql = mysql_query("SELECT * FROM {$table_name} WHERE {$prime_key} ='{$lite_specific_id}'") or die("Error 98: " . mysql_error());
                    $dup_sql = "SELECT * FROM {$table_name} WHERE {$prime_key} ='{$lite_specific_id}'";
                    //echo "DTEST";
                }
                unset($all_keys);
            }
            if (mysql_num_rows($get_data_sql) == 0) {
                $emr_px_id = $emr_px_id;
            }
            $get_data_result = mysql_fetch_array($get_data_sql);
            $field_count = mysql_num_fields($get_data_sql);
            for ($i = 0; $i < $field_count; $i++) {
                //echo "why oh why? : $lite_specific_id";
                $field_name = mysql_field_name($get_data_sql, $i);
                switch ($field_name) {
                    case 'patient_id':
                        if ($emr_px_id == 0) {
                            array_push($data_array, 'na');
                        } else {
                            array_push($data_array, $emr_px_id);
                        }
                        break;
                    case 'consult_id':
                        if ($get_data_result[$field_name]) {
                            //echo "CONSULT_ID : $lite_specific_id";
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_consult', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'mc_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_patient_mc', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'fp_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_patient_fp', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'notes_id':
                        if ($sync_type == 'D') {
                            $emr_id = $emr_specific_id;
                        } else {
                            if ($get_data_result[$field_name]) {
                                $lite_specific_id = $get_data_result[$field_name];
                            }
                            $emr_id = get_existing_id('m_consult_notes', $field_name, $lite_specific_id);
                        }
                        //echo "ABOT ".$emr_id;
                        array_push($data_array, $emr_id);
                        //print_r($data_array);
                        break;
                    case 'dropout_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_patient_fp_dropout', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'family_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_family', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'cct_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_family_cct_member', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'ccdev_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_patient_ccdev', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'request_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_consult_lab', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'ntp_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_patient_ntp', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'symptomatic_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_consult_ntp_symptopmatics', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'report_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_patient_ntp_report', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'reminder_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_consult_reminder', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'fp_px_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_patient_fp_method', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    case 'schedule_id':
                        if ($get_data_result[$field_name]) {
                            $lite_specific_id = $get_data_result[$field_name];
                        }
                        $emr_id = get_existing_id('m_consult_appointments', $field_name, $lite_specific_id);
                        array_push($data_array, $emr_id);
                        break;
                    default:
                        array_push($data_array, $get_data_result[$i]);
                        break;
                }
            }
            //start of checking for duplicate
            $duplicate = 0;
            $inside_array = array($data_array[4], $data_array[7], $data_array[8]);
            array_push($collect_array, $inside_array);
            if (in_array($data_array, $all_array)) {
                //check for same entry in array
                switch ($data_array[4]) {
                    //check duplicate entry base on primary key, default will move the cursor to next record
                    case 'm_consult_ccdev_services' || 'm_consult_vaccine' || 'm_consult_ccdev_vaccine':
                        $inside_array = array($data_array[4], $data_array[7], $data_array[8]);
                        if (in_array($inside_array, $collect_array)) {
                            ${$data_array}[4] = ${$data_array}[4] + 1;
                        }
                        break;
                    case 'm_consult_ccdev_vaccines':
                        $inside_array = array($data_array[4], $data_array[7], $data_array[8]);
                        if (in_array($inside_array, $collect_array)) {
                            ${$data_array}[4] = ${$data_array}[4] + 1;
                        }
                        break;
                    default:
                        ${$data_array}[4] = ${$data_array}[4] + 1;
                        break;
                }
                $duplicate = ${$data_array}[4];
                echo $data_array[4] . " id :" . $duplicate . "<br />";
                unset($inside_array);
            }
            if ($duplicate >= 1) {
                //Go to next row if duplicate was found
                unset($data_array);
                //echo "LITE ID : ".$lite_specific_id;
                $data_array = array($lite_px_id, $emr_px_id, $lite_id, $emr_specific_id, $table_name, $entry_date, $sync_type);
                $dup_sql_con = $dup_sql . " LIMIT {$duplicate}, 1";
                //echo "SQL NOW! $dup_sql_con";
                $dup_query = mysql_query($dup_sql_con);
                $get_ids = mysql_fetch_array($dup_query);
                $field_count = mysql_num_fields($dup_query);
                for ($i = 0; $i < $field_count; $i++) {
                    $field_name = mysql_field_name($dup_query, $i);
                    switch ($field_name) {
                        case 'patient_id':
                            if ($emr_px_id == 0) {
                                array_push($data_array, 'na');
                            } else {
                                array_push($data_array, $emr_px_id);
                            }
                            break;
                        case 'consult_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_consult', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'mc_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_patient_mc', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'fp_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_patient_fp', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'fp_px_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_patient_fp_method', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'notes_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            //echo "EMR ID = $lite_specific_id";
                            $emr_id = get_existing_id('m_consult_notes', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'dropout_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_patient_fp_dropout', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'family_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_family', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'cct_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_family_cct_member', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'ccdev_id':
                            if ($get_ids['ccdev_id']) {
                                $lite_specific_id = $get_ids['ccdev_id'];
                            }
                            $emr_id = get_existing_id('m_patient_ccdev', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'request_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_consult_lab', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'ntp_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_patient_ntp', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'symptomatic_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_consult_ntp_symptopmatics', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'report_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_patient_ntp_report', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'reminder_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_consult_reminder', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'fp_px_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_patient_fp_method', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        case 'schedule_id':
                            if ($get_ids[$field_name]) {
                                $lite_specific_id = $get_ids[$field_name];
                            }
                            $emr_id = get_existing_id('m_consult_appointments', $field_name, $lite_specific_id);
                            array_push($data_array, $emr_id);
                            break;
                        default:
                            array_push($data_array, $get_ids[$i]);
                            break;
                    }
                }
                array_push($all_array, $data_array);
            } else {
                //If no duplicate was detected
                array_push($all_array, $data_array);
            }
            unset($data_array);
            $data_array = array();
        }
        //end of while
    }
    return $all_array;
}
예제 #2
0
function get_data_array($check_status_sql)
{
    $check_status_query = mysql_query("{$check_status_sql}") or die("Error 57: " . mysql_error());
    if (mysql_num_rows($check_status_query)) {
        //create an array of all the entry in ehr_lite when m_push_status = 'Y'
        if (!isset($all_array)) {
            $all_array = array();
        } else {
            unset($all_array);
        }
        while (list($lite_px_id, $emr_px_id, $lite_specific_id, $emr_specific_id, $table_name, $entry_date, $sync_type) = mysql_fetch_array($check_status_query)) {
            $data_array = array($lite_px_id, $emr_px_id, $lite_specific_id, $emr_specific_id, $table_name, $entry_date, $sync_type);
            $prime_key_sql = mysql_query("SELECT * FROM {$table_name}") or die("Error 88 :" . mysql_error());
            $prime_key = mysql_field_name($prime_key_sql, 0);
            //Get all information from the specific table name
            if ($table_name == 'm_patient') {
                $get_data_sql = mysql_query("SELECT * FROM {$table_name} WHERE patient_id ='{$lite_px_id}'") or die("Error 93: " . mysql_error());
            } else {
                $get_data_sql = mysql_query("SELECT * FROM {$table_name} WHERE {$prime_key} ='{$lite_specific_id}' AND patient_id ='{$lite_px_id}'") or die("Error 95: " . mysql_error());
            }
            if (mysql_num_rows($get_data_sql) != 0) {
                $get_data_result = mysql_fetch_array($get_data_sql);
                $field_count = mysql_num_fields($get_data_sql);
                for ($i = 0; $i < $field_count; $i++) {
                    $field_name = mysql_field_name($get_data_sql, $i);
                    switch ($field_name) {
                        case 'patient_id':
                            if ($emr_px_id == 0) {
                                array_push($data_array, 'na');
                            } else {
                                array_push($data_array, $emr_px_id);
                            }
                            break;
                        case 'consult_id':
                            $emr_id = get_existing_id('m_consult', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'mc_id':
                            $emr_id = get_existing_id('m_patient_mc', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'fp_id':
                            $emr_id = get_existing_id('m_patient_fp', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'notes_id':
                            $emr_id = get_existing_id('m_consult_fp', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'fp_service_id':
                            $emr_id = get_existing_id('m_patient_fp_method_service', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'dropout_id':
                            $emr_id = get_existing_id('m_patient_fp_dropout', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'family_id':
                            $emr_id = get_existing_id('m_family', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'cct_id':
                            $emr_id = get_existing_id('m_family_cct_members', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'ccdev_id':
                            $emr_id = get_existing_id('m_patient_ccdev', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'request_id':
                            $emr_id = get_existing_id('m_consult_lab', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'ntp_id':
                            $emr_id = get_existing_id('m_patient_ntp', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'symptomatic_id':
                            $emr_id = get_existing_id('m_consult_ntp_symptopmatics', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'report_id':
                            $emr_id = get_existing_id('m_patient_ntp_report', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'reminder_id':
                            $emr_id = get_existing_id('m_consult_reminder', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'fp_px_id':
                            $emr_id = get_existing_id('m_patient_fp_method', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        case 'schedule_id':
                            $emr_id = get_existing_id('m_consult_appointments', $field_name);
                            array_push($data_array, $emr_id);
                            break;
                        default:
                            array_push($data_array, $get_data_result[$i]);
                            break;
                    }
                }
                array_push($all_array, $data_array);
                unset($data_array);
                $data_array = array();
            }
        }
    }
    return $all_array;
}