"TPA Policy Number", "db_column" => "tpa_policy_number"], ["excel_column" => "Insurer Policy Number", "db_column" => "insurer_policy_number"], ["excel_column" => "Corporate Name", "db_column" => "corporate_name"], ["excel_column" => "Proposer Name", "db_column" => "proposer_name"], ["excel_column" => "Corporate Group ID", "db_column" => "corporate_group_id"], ["excel_column" => "Policy Start Date", "db_column" => "policy_start_date"], ["excel_column" => "Policy End date", "db_column" => "policy_end_date"], ["excel_column" => "Insurance Company Name", "db_column" => "insurance_company_name"], ["excel_column" => "Employee Number", "db_column" => "employee_number"], ["excel_column" => "Employee Location", "db_column" => "employee_location"], ["excel_column" => "Primary Policy Holder Name", "db_column" => "primary_policy_holder_name"], ["excel_column" => "Primary Policy Holder Card ID", "db_column" => "primary_policy_holder_card_id"], ["excel_column" => "Employee Grade", "db_column" => "employee_grade"], ["excel_column" => "Patient Health Card ID", "db_column" => "patient_health_card_id"], ["excel_column" => "Patient Name", "db_column" => "patient_name"], ["excel_column" => "Date of Birth", "db_column" => "date_of_birth"], ["excel_column" => "Age", "db_column" => "age"], ["excel_column" => "Gender", "db_column" => "gender"], ["excel_column" => "Relation", "db_column" => "relation"], ["excel_column" => "Sum Insured", "db_column" => "sum_insured"], ["excel_column" => "Balance Sum Insured", "db_column" => "balance_sum_insured"], ["excel_column" => "Top Up Sum Insured", "db_column" => "top_up_sum_insured"], ["excel_column" => "Enrollment status", "db_column" => "enrollment_status"], ["excel_column" => "Policy Inception date", "db_column" => "policy_inception_date"], ["excel_column" => "Policy Exit Date", "db_column" => "policy_exit_date"], ["excel_column" => "Insurer Risk ID", "db_column" => "insurer_risk_id"], ["excel_column" => "Claim Preauth Identifier", "db_column" => "claim_preauth_identifier"], ["excel_column" => "TPA Claim Number", "db_column" => "tpa_claim_number"], ["excel_column" => "Preauth Number", "db_column" => "preauth_number"], ["excel_column" => "Insurer Claim Number", "db_column" => "insurer_claim_number"], ["excel_column" => "Claim Received date", "db_column" => "claim_received_date"], ["excel_column" => "Date of Admission", "db_column" => "date_of_admission"], ["excel_column" => "Date of Discharge", "db_column" => "date_of_discharge"], ["excel_column" => "Hospital Name", "db_column" => "hospital_name"], ["excel_column" => "Hospital ID", "db_column" => "hospital_id"], ["excel_column" => "Hospital Address", "db_column" => "hospital_address"], ["excel_column" => "Hospital City", "db_column" => "hospital_city"], ["excel_column" => "Hospital State", "db_column" => "hospital_state"], ["excel_column" => "Hospital Pincode", "db_column" => "hospital_pincode"], ["excel_column" => "Hospital Network status", "db_column" => "hospital_network_status"], ["excel_column" => "PPN Hospital Status", "db_column" => "ppn_hospital_status"], ["excel_column" => "Room Category", "db_column" => "room_category"], ["excel_column" => "Room Days", "db_column" => "room_days"], ["excel_column" => "ICU Days", "db_column" => "icu_days"], ["excel_column" => "Medical Surgical Identifier", "db_column" => "medical_surgical_identifier"], ["excel_column" => "Treatment Type of AYUSH", "db_column" => "treatment_type_of_ayush"], ["excel_column" => "Package", "db_column" => "package"], ["excel_column" => "Diagnosis", "db_column" => "diagnosis"], ["excel_column" => "Illness Details", "db_column" => "illness_details"], ["excel_column" => "Ailment Grouping", "db_column" => "ailment_grouping"], ["excel_column" => "Primary ICD Code", "db_column" => "primary_icd_code"], ["excel_column" => "Secondary ICD Code", "db_column" => "secondary_icd_code"], ["excel_column" => "Procedure Code", "db_column" => "procedure_code"], ["excel_column" => "Procedure Description", "db_column" => "procedure_description"], ["excel_column" => "Procedure Grouping", "db_column" => "procedure_grouping"], ["excel_column" => "Claim Submission mode", "db_column" => "claim_submission_mode"], ["excel_column" => "Admission Category", "db_column" => "admission_category"], ["excel_column" => "Type of Claim", "db_column" => "type_of_claim"], ["excel_column" => "MainClaim_Prepost type", "db_column" => "mainclaim_prepost_type"], ["excel_column" => "Type of Hospitalization", "db_column" => "type_of_hospitalization"], ["excel_column" => "Death Status", "db_column" => "death_status"], ["excel_column" => "Treatement Given", "db_column" => "treatment_given"], ["excel_column" => "Claim Amount", "db_column" => "claim_amount"], ["excel_column" => "Total Billed Amount", "db_column" => "total_billed_amount"], ["excel_column" => "Claim Consultation Charges", "db_column" => "claim_consultation_charges"], ["excel_column" => "Claim Investigation Charges", "db_column" => "claim_investigation_charges"], ["excel_column" => "Claim Medicines", "db_column" => "claim_medicines"], ["excel_column" => "Claim Nursing", "db_column" => "claim_nursing"], ["excel_column" => "Claim Room Charges", "db_column" => "claim_room_charges"], ["excel_column" => "Claim Icu Charges", "db_column" => "claim_icu_charges"], ["excel_column" => "Claim Stay Charges", "db_column" => "claim_stay_charges"], ["excel_column" => "Claim Surgeon Charges", "db_column" => "claim_surgeon_charges"], ["excel_column" => "Claim Surgery Charges", "db_column" => "claim_surgery_charges"], ["excel_column" => "Claim Miscellaneous Charges", "db_column" => "claim_miscellaneous_charges"], ["excel_column" => "Claim Other Charges", "db_column" => "claim_other_charges"], ["excel_column" => "Approved Consultation Charges", "db_column" => "approved_consultation_charges"], ["excel_column" => "Approved Investigation Charges", "db_column" => "approved_investigation_charges"], ["excel_column" => "Approved Medicines", "db_column" => "approved_medicines"], ["excel_column" => "Approved Nursing", "db_column" => "approved_nursing"], ["excel_column" => "Approved Room Charges", "db_column" => "approved_room_charges"], ["excel_column" => "Approved Icu Charges", "db_column" => "approved_icu_charges"], ["excel_column" => "Approved Stay Charges", "db_column" => "approved_stay_charges"], ["excel_column" => "Approved Surgeon Charges", "db_column" => "approved_surgeon_charges"], ["excel_column" => "Approved Surgery Charges", "db_column" => "approved_surgery_charges"], ["excel_column" => "Approved Miscellaneous Charges", "db_column" => "approved_miscellaneous_charges"], ["excel_column" => "Approved Others Charges", "db_column" => "approved_others_charges"], ["excel_column" => "Total Disallowed Amount", "db_column" => "total_disallowed_amount"], ["excel_column" => "Copayment Amount", "db_column" => "copayment_amount"], ["excel_column" => "Deposit Amount", "db_column" => "deposit_amount"], ["excel_column" => "Exceeds Policy Limit", "db_column" => "exceeds_policy_limit"], ["excel_column" => "Copay Buffer", "db_column" => "copay_buffer"], ["excel_column" => "Hospital Discount Amount", "db_column" => "hospital_discount_amount"], ["excel_column" => "Deductible Amount", "db_column" => "deductible_amount"], ["excel_column" => "Approved Amount", "db_column" => "approved_amount"], ["excel_column" => "Total Incurred Amount", "db_column" => "total_incurred_amount"], ["excel_column" => "Total Buffer Approved", "db_column" => "total_buffer_approved"], ["excel_column" => "Total Buffer Utlilized", "db_column" => "total_buffer_utilized"], ["excel_column" => "TDS Amount", "db_column" => "tds_amount"], ["excel_column" => "Net Amount", "db_column" => "net_amount"], ["excel_column" => "Claim Decision date", "db_column" => "claim_decision_date"], ["excel_column" => "Payment Reference Number", "db_column" => "payment_reference_number"], ["excel_column" => "Payment Reference Date", "db_column" => "payment_reference_date"], ["excel_column" => "Claim Status", "db_column" => "claim_status"], ["excel_column" => "Deduction Remarks", "db_column" => "deduction_remarks"], ["excel_column" => "Rejection Reasons", "db_column" => "rejection_reasons"], ["excel_column" => "Claim Query Reasons", "db_column" => "claim_query_reasons"], ["excel_column" => "Insurer Request Sent date", "db_column" => "insurer_request_sent_date"], ["excel_column" => "Insurer Conf. Received date", "db_column" => "insurer_conf_received_date"], ["excel_column" => "Claim Reopen Date", "db_column" => "claim_reopen_date"], ["excel_column" => "First Query Raised date", "db_column" => "first_query_raised_date"], ["excel_column" => "First Query response date", "db_column" => "first_query_response_date"], ["excel_column" => "Last Query Raised date", "db_column" => "last_query_raised_date"], ["excel_column" => "Last Query response date", "db_column" => "last_query_response_date"], ["excel_column" => "Last Document Received date", "db_column" => "last_document_received_date"], ]; protected $mapping = [ ["excel_column" => ["col_name" => "TPA Policy Number", "col_index" => 0], "db_column" => "tpa_policy_number"], ["excel_column" => ["col_name" => "Insurer Policy Number", "col_index" => 1], "db_column" => "insurer_policy_number"], ["excel_column" => ["col_name" => "Corporate Name", "col_index" => 2], "db_column" => "corporate_name"], ["excel_column" => ["col_name" => "Proposer Name", "col_index" => 3], "db_column" => "proposer_name"], ["excel_column" => ["col_name" => "Corporate Group ID", "col_index" => 4], "db_column" => "corporate_group_id"], ["excel_column" => ["col_name" => "Policy Start Date", "col_index" => 5], "db_column" => "policy_start_date"], ["excel_column" => ["col_name" => "Policy End date", "col_index" => 6], "db_column" => "policy_end_date"], ["excel_column" => ["col_name" => "Insurance Company Name", "col_index" => 7], "db_column" => "insurance_company_name"], ["excel_column" => ["col_name" => "Employee Number", "col_index" => 8], "db_column" => "employee_number"], ["excel_column" => ["col_name" => "Employee Location", "col_index" => 9], "db_column" => "employee_location"], ["excel_column" => ["col_name" => "Primary Policy Holder Name", "col_index" => 10], "db_column" => "primary_policy_holder_name"], ["excel_column" => ["col_name" => "Primary Policy Holder Card ID", "col_index" => 11], "db_column" => "primary_policy_holder_card_id"], ["excel_column" => ["col_name" => "Employee Grade", "col_index" => 12], "db_column" => "employee_grade"], ["excel_column" => ["col_name" => "Patient Health Card ID", "col_index" => 13], "db_column" => "patient_health_card_id"], ["excel_column" => ["col_name" => "Patient Name", "col_index" => 14], "db_column" => "patient_name"], ["excel_column" => ["col_name" => "Date of Birth", "col_index" => 15], "db_column" => "date_of_birth"], ["excel_column" => ["col_name" => "Age", "col_index" => 16], "db_column" => "age"], ["excel_column" => ["col_name" => "Gender", "col_index" => 17], "db_column" => "gender"], ["excel_column" => ["col_name" => "Relation", "col_index" => 18], "db_column" => "relation"], ["excel_column" => ["col_name" => "Sum Insured", "col_index" => 19], "db_column" => "sum_insured"], ["excel_column" => ["col_name" => "Balance Sum Insured", "col_index" => 20], "db_column" => "balance_sum_insured"], ["excel_column" => ["col_name" => "Top Up Sum Insured", "col_index" => 21], "db_column" => "top_up_sum_insured"], ["excel_column" => ["col_name" => "Enrollment status", "col_index" => 22], "db_column" => "enrollment_status"], ["excel_column" => ["col_name" => "Policy Inception date", "col_index" => 23], "db_column" => "policy_inception_date"], ["excel_column" => ["col_name" => "Policy Exit Date", "col_index" => 24], "db_column" => "policy_exit_date"], ["excel_column" => ["col_name" => "Insurer Risk ID", "col_index" => 25], "db_column" => "insurer_risk_id"], ["excel_column" => ["col_name" => "Claim Preauth Identifier", "col_index" => 26], "db_column" => "claim_preauth_identifier"], ["excel_column" => ["col_name" => "TPA Claim Number", "col_index" => 27], "db_column" => "tpa_claim_number"], ["excel_column" => ["col_name" => "Preauth Number", "col_index" => 28], "db_column" => "preauth_number"], ["excel_column" => ["col_name" => "Insurer Claim Number", "col_index" => 29], "db_column" => "insurer_claim_number"], ["excel_column" => ["col_name" => "Claim Received date", "col_index" => 30], "db_column" => "claim_received_date"], ["excel_column" => ["col_name" => "Date of Admission", "col_index" => 31], "db_column" => "date_of_admission"], ["excel_column" => ["col_name" => "Date of Discharge", "col_index" => 32], "db_column" => "date_of_discharge"], ["excel_column" => ["col_name" => "Hospital Name", "col_index" => 33], "db_column" => "hospital_name"], ["excel_column" => ["col_name" => "Hospital ID", "col_index" => 34], "db_column" => "hospital_id"], ["excel_column" => ["col_name" => "Hospital Address", "col_index" => 35], "db_column" => "hospital_address"], ["excel_column" => ["col_name" => "Hospital City", "col_index" => 36], "db_column" => "hospital_city"], ["excel_column" => ["col_name" => "Hospital State", "col_index" => 37], "db_column" => "hospital_state"], ["excel_column" => ["col_name" => "Hospital Pincode", "col_index" => 38], "db_column" => "hospital_pincode"], ["excel_column" => ["col_name" => "Hospital Network status", "col_index" => 39], "db_column" => "hospital_network_status"], ["excel_column" => ["col_name" => "PPN Hospital Status", "col_index" => 40], "db_column" => "ppn_hospital_status"], ["excel_column" => ["col_name" => "Room Category", "col_index" => 41], "db_column" => "room_category"], ["excel_column" => ["col_name" => "Room Days", "col_index" => 42], "db_column" => "room_days"], ["excel_column" => ["col_name" => "ICU Days", "col_index" => 43], "db_column" => "icu_days"], ["excel_column" => ["col_name" => "Medical Surgical Identifier", "col_index" => 44], "db_column" => "medical_surgical_identifier"], ["excel_column" => ["col_name" => "Treatment Type of AYUSH", "col_index" => 45], "db_column" => "treatment_type_of_ayush"], ["excel_column" => ["col_name" => "Package", "col_index" => 46], "db_column" => "package"], ["excel_column" => ["col_name" => "Diagnosis", "col_index" => 47], "db_column" => "diagnosis"], ["excel_column" => ["col_name" => "Illness Details", "col_index" => 48], "db_column" => "illness_details"], ["excel_column" => ["col_name" => "Ailment Grouping", "col_index" => 49], "db_column" => "ailment_grouping"], ["excel_column" => ["col_name" => "Primary ICD Code", "col_index" => 50], "db_column" => "primary_icd_code"], ["excel_column" => ["col_name" => "Secondary ICD Code", "col_index" => 51], "db_column" => "secondary_icd_code"], ["excel_column" => ["col_name" => "Procedure Code", "col_index" => 52], "db_column" => "procedure_code"], ["excel_column" => ["col_name" => "Procedure Description", "col_index" => 53], "db_column" => "procedure_description"], ["excel_column" => ["col_name" => "Procedure Grouping", "col_index" => 54], "db_column" => "procedure_grouping"], ["excel_column" => ["col_name" => "Claim Submission mode", "col_index" => 55], "db_column" => "claim_submission_mode"], ["excel_column" => ["col_name" => "Admission Category", "col_index" => 56], "db_column" => "admission_category"], ["excel_column" => ["col_name" => "Type of Claim", "col_index" => 57], "db_column" => "type_of_claim"], ["excel_column" => ["col_name" => "MainClaim_Prepost type", "col_index" => 58], "db_column" => "mainclaim_prepost_type"], ["excel_column" => ["col_name" => "Type of Hospitalization", "col_index" => 59], "db_column" => "type_of_hospitalization"], ["excel_column" => ["col_name" => "Death Status", "col_index" => 60], "db_column" => "death_status"], ["excel_column" => ["col_name" => "Treatement Given", "col_index" => 61], "db_column" => "treatment_given"], ["excel_column" => ["col_name" => "Claim Amount", "col_index" => 62], "db_column" => "claim_amount"], ["excel_column" => ["col_name" => "Total Billed Amount", "col_index" => 63], "db_column" => "total_billed_amount"], ["excel_column" => ["col_name" => "Claim Consultation Charges", "col_index" => 64], "db_column" => "claim_consultation_charges"], ["excel_column" => ["col_name" => "Claim Investigation Charges", "col_index" => 65], "db_column" => "claim_investigation_charges"], ["excel_column" => ["col_name" => "Claim Medicines", "col_index" => 66], "db_column" => "claim_medicines"], ["excel_column" => ["col_name" => "Claim Nursing", "col_index" => 67], "db_column" => "claim_nursing"], ["excel_column" => ["col_name" => "Claim Room Charges", "col_index" => 68], "db_column" => "claim_room_charges"], ["excel_column" => ["col_name" => "Claim Icu Charges", "col_index" => 69], "db_column" => "claim_icu_charges"], ["excel_column" => ["col_name" => "Claim Stay Charges", "col_index" => 70], "db_column" => "claim_stay_charges"], ["excel_column" => ["col_name" => "Claim Surgeon Charges", "col_index" => 71], "db_column" => "claim_surgeon_charges"], ["excel_column" => ["col_name" => "Claim Surgery Charges", "col_index" => 72], "db_column" => "claim_surgery_charges"], ["excel_column" => ["col_name" => "Claim Miscellaneous Charges", "col_index" => 73], "db_column" => "claim_miscellaneous_charges"], ["excel_column" => ["col_name" => "Claim Other Charges", "col_index" => 74], "db_column" => "claim_other_charges"], ["excel_column" => ["col_name" => "Approved Consultation Charges", "col_index" => 75], "db_column" => "approved_consultation_charges"], ["excel_column" => ["col_name" => "Approved Investigation Charges", "col_index" => 76], "db_column" => "approved_investigation_charges"], ["excel_column" => ["col_name" => "Approved Medicines", "col_index" => 77], "db_column" => "approved_medicines"], ["excel_column" => ["col_name" => "Approved Nursing", "col_index" => 78], "db_column" => "approved_nursing"], ["excel_column" => ["col_name" => "Approved Room Charges", "col_index" => 79], "db_column" => "approved_room_charges"], ["excel_column" => ["col_name" => "Approved Icu Charges", "col_index" => 80], "db_column" => "approved_icu_charges"], ["excel_column" => ["col_name" => "Approved Stay Charges", "col_index" => 81], "db_column" => "approved_stay_charges"], ["excel_column" => ["col_name" => "Approved Surgeon Charges", "col_index" => 82], "db_column" => "approved_surgeon_charges"], ["excel_column" => ["col_name" => "Approved Surgery Charges", "col_index" => 83], "db_column" => "approved_surgery_charges"], ["excel_column" => ["col_name" => "Approved Miscellaneous Charges", "col_index" => 84], "db_column" => "approved_miscellaneous_charges"], ["excel_column" => ["col_name" => "Approved Others Charges", "col_index" => 85], "db_column" => "approved_others_charges"], ["excel_column" => ["col_name" => "Total Disallowed Amount", "col_index" => 86], "db_column" => "total_disallowed_amount"], ["excel_column" => ["col_name" => "Copayment Amount", "col_index" => 87], "db_column" => "copayment_amount"], ["excel_column" => ["col_name" => "Deposit Amount", "col_index" => 88], "db_column" => "deposit_amount"], ["excel_column" => ["col_name" => "Exceeds Policy Limit", "col_index" => 89], "db_column" => "exceeds_policy_limit"], ["excel_column" => ["col_name" => "Copay Buffer", "col_index" => 90], "db_column" => "copay_buffer"], ["excel_column" => ["col_name" => "Hospital Discount Amount", "col_index" => 91], "db_column" => "hospital_discount_amount"], ["excel_column" => ["col_name" => "Deductible Amount", "col_index" => 92], "db_column" => "deductible_amount"], ["excel_column" => ["col_name" => "Approved Amount", "col_index" => 93], "db_column" => "approved_amount"], ["excel_column" => ["col_name" => "Total Incurred Amount", "col_index" => 94], "db_column" => "total_incurred_amount"], ["excel_column" => ["col_name" => "Total Buffer Approved", "col_index" => 95], "db_column" => "total_buffer_approved"], ["excel_column" => ["col_name" => "Total Buffer Utlilized", "col_index" => 96], "db_column" => "total_buffer_utilized"], ["excel_column" => ["col_name" => "TDS Amount", "col_index" => 97], "db_column" => "tds_amount"], ["excel_column" => ["col_name" => "Net Amount", "col_index" => 98], "db_column" => "net_amount"], ["excel_column" => ["col_name" => "Claim Decision date", "col_index" => 99], "db_column" => "claim_decision_date"], ["excel_column" => ["col_name" => "Payment Reference Number", "col_index" => 100], "db_column" => "payment_reference_number"], ["excel_column" => ["col_name" => "Payment Reference Date", "col_index" => 101], "db_column" => "payment_reference_date"], ["excel_column" => ["col_name" => "Claim Status", "col_index" => 102], "db_column" => "claim_status"], ["excel_column" => ["col_name" => "Deduction Remarks", "col_index" => 103], "db_column" => "deduction_remarks"], ["excel_column" => ["col_name" => "Rejection Reasons", "col_index" => 104], "db_column" => "rejection_reasons"], ["excel_column" => ["col_name" => "Claim Query Reasons", "col_index" => 105], "db_column" => "claim_query_reasons"], ["excel_column" => ["col_name" => "Insurer Request Sent date", "col_index" => 106], "db_column" => "insurer_request_sent_date"], ["excel_column" => ["col_name" => "Insurer Conf. Received date", "col_index" => 107], "db_column" => "insurer_conf_received_date"], ["excel_column" => ["col_name" => "Claim Reopen Date", "col_index" => 108], "db_column" => "claim_reopen_date"], ["excel_column" => ["col_name" => "First Query Raised date", "col_index" => 109], "db_column" => "first_query_raised_date"], ["excel_column" => ["col_name" => "First Query response date", "col_index" => 110], "db_column" => "first_query_response_date"], ["excel_column" => ["col_name" => "Last Query Raised date", "col_index" => 111], "db_column" => "last_query_raised_date"], ["excel_column" => ["col_name" => "Last Query response date", "col_index" => 112], "db_column" => "last_query_response_date"], ["excel_column" => ["col_name" => "Last Document Received date", "col_index" => 113], "db_column" => "last_document_received_date"], ]; protected $ticketMasterMapping = [ // Policy / Claim identifiers 'insurer_claim_number' => 'claim_number', 'tpa_claim_number' => 'tpa_claim_id', // Employee / Insured details 'employee_number' => 'emp_code', 'primary_policy_holder_name' => 'emp_name', 'patient_name' => 'insured_name', // Dates 'date_of_admission' => 'doa', 'date_of_discharge' => 'dod', 'date_of_birth' => 'dob', 'claim_received_date' => 'registration_date', // Claim details 'claim_amount' => 'claim_amount', 'approved_amount' => 'approved_amount', 'sum_insured' => 'si_amt', 'claim_status' => 'tpa_claim_status', // Hospital details 'hospital_name' => 'hospital_name', 'hospital_address' => 'hospital_address', 'hospital_city' => 'hospital_city', 'hospital_state' => 'hospital_state', 'hospital_pincode' => 'hospital_pin_code', // Meta 'file_id' => 'file_id', 'type_of_claim' => 'tpa_claim_type', 'diagnosis' => 'tpa_ailments', ]; /** * Extra dump → claim_report fields beyond ticketMasterMapping. protected $statusMapping = [ 'Settled' => 11, 'Rejected' => 8, 'Paid' => 11, 'Denied' => 8, 'Cancelled' => 13, 'Processed' => 61, 'Information Awaited' => 4, 'Denied Letter Sent' => 66, 'Cashless Document Awaited' => 3, 'Approved' => 9, 'Closed' => 12, ]; /** * ABSTRACT FUNCTIONs */ public function bulkInsertTPATable(array $data): bool { if (empty($data)) { return false; } $builder = $this->db->table('claims_dump_vidal'); return $builder->insertBatch($data); } public function importClaimMaster(array $data): bool { if (empty($data)) { return false; } $ticketMasterModel = new TicketMasterModel(); return $ticketMasterModel->insertBatch($data); } public function updateTicketIdInTPATable(int $fileId): bool { $rows = $this->db->table('claims_dump_vidal cd') ->select('cd.id, tm.id AS ticket_id') ->join('ticket_master tm', 'tm.claim_dump_ref_id = cd.id AND tm.file_id = cd.file_id', 'inner') ->where('cd.is_active', 1) ->where('cd.file_id', $fileId) ->where('cd.ticket_id IS NULL') ->get() ->getResultArray(); if (empty($rows)) { return true; } $updateData = []; foreach ($rows as $row) { $updateData[] = [ 'id' => $row['id'], 'ticket_id' => $row['ticket_id'], ]; } return $this->db->table('claims_dump_vidal')->updateBatch($updateData, 'id') !== false; } public function updateTicketMasterRejectedReasonInTPATable($data): bool { if (empty($data)) { return false; } $builder = $this->db->table('claims_dump_vidal'); return $builder->updateBatch($data, 'id') !== false; } /** * MAPPING FUNCTIONs */ public function mapTPAData(array $rows, $file_id): array { $ClientPolicyModel = new ClaimDumpFileModel(); $file_data = $ClientPolicyModel->where('id', $file_id)->first(); $mapped = []; foreach ($rows as $row) { $item = []; foreach ($this->mapping as $map) { $excelColumn = $map['excel_column']['col_name']; $dbColumn = $map['db_column']; $value = $row[$excelColumn] ?? null; if ($this->isDateValue($value)) { $value = $this->normalizeDate($value); } $item[$dbColumn] = $value; } $item['file_id'] = $file_id ?? null; $item['client_id'] = $file_data['client_id'] ?? null; $item['client_policy_id'] = $file_data['client_policy_id'] ?? null; $item['created_by'] = $file_data['created_by'] ?? null; $mapped[] = $item; } return $mapped; } public function mapClaimMasterData($file_id): array { $ClientPolicyModel = new ClaimDumpFileModel(); $file_data = $ClientPolicyModel->where('id', $file_id)->first(); $tpaClaimDumpData = $this->getTpaClaimDumpData('claims_dump_vidal', ['file_id' => $file_id]); if (empty($tpaClaimDumpData)) { return $this->emptyClaimMasterMappingResponse('claims_dump_vidal', (int) $file_id); } $ClientPolicyModel = new ClientPolicyModel(); $client_policy_data = $ClientPolicyModel ->select(" client_policy.*, ( SELECT id FROM client_rm WHERE is_active = 1 AND level = 3 AND client_id = client_policy.client_id ORDER BY id ASC LIMIT 1 ) AS acm_id ") ->where('client_policy.id', $file_data['client_policy_id']) ->where('client_policy.is_active', 1) ->first(); try { $mapped = []; $rejecetd_reason = []; $status_update_array = []; foreach ($tpaClaimDumpData as $row) { $params = [ 'doa' => change_date_format($row['date_of_admission'] ?? '') ?? null, 'emp_code' => $row['employee_number'] ?? null, 'claim_amount' => $row['claim_amount'] ?? null, 'tpa_no' => $row['primary_policy_holder_card_id'] ?? null, 'client_id' => $file_data['client_id'] ?? null, 'client_policy_id' => $file_data['client_policy_id'] ?? null, ]; $newStatusId = $this->resolveClaimStatusId( $this->statusMapping, $row['claim_status'] ?? '', (int) $row['id'], $rejecetd_reason ); if ($newStatusId === null) { continue; } $existingTicket = $this->getExistingTicketMasterClaim($params); if ($this->handleExistingTicketStatusUpdate( $existingTicket, $newStatusId, (int) $row['id'], $status_update_array, $rejecetd_reason )) { continue; } $item = []; $item['client_id'] = $client_policy_data['client_id'] ?? null; $item['client_policy_id'] = $client_policy_data['id'] ?? null; $item['insurer_id'] = $client_policy_data['insurer_id'] ?? null; $item['tpa_id'] = $client_policy_data['tpa_id'] ?? null; $item['acm_id'] = $client_policy_data['acm_id'] ?? null; $item['policy_no'] = $client_policy_data['policy_no'] ?? null; $item['relationship'] = $this->convertRelation($row['relation'] ?? null, $row['gender'] ?? null); $employee_data = $this->getEmployeeDetails($file_data['client_id'], $file_data['client_policy_id'], $row['employee_number'], $item['relationship']); if (!empty($employee_data)) { $item['emp_id'] = $employee_data['id'] ?? null; $item['emp_name'] = $employee_data['name'] ?? null; $item['emp_mail'] = $employee_data['emp_mail'] ?? null; $item['emp_code'] = $employee_data['emp_code'] ?? null; $item['emp_mobile'] = $employee_data['emp_mobile'] ?? null; $item['insured_emp_id'] = $employee_data['insured_emp_id'] ?? null; $item['insured_name'] = $employee_data['insured_name'] ?? null; } else { $reason = 'This employee not exist in our system.'; $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } foreach ($this->ticketMasterMapping as $tpaKey => $ticketMasterKey) { $item[$ticketMasterKey] = array_key_exists($tpaKey, $row) ? $row[$tpaKey] : null; } // Meta fields $item['claim_status_id'] = $newStatusId; $item['file_id'] = $file_id; $item['claim_dump_ref_id'] = $row['id']; $item['claim_dump_date'] = $file_data['claim_dump_date'] ?? null; $item['created_by'] = $file_data['created_by'] ?? null; $item['claim_type'] = isset($row['mainclaim_prepost_type']) && !empty($row['mainclaim_prepost_type']) && strtolower($row['mainclaim_prepost_type']) == 'normal' ? 1 : 3; $item['priority'] = 1; $item['mode_of_intimation'] = 5; $item['ticket_type_id'] = 1; $item['claim_created_by'] = 'DUMP_TPA'; $mapped[] = $item; } return [ 'status' => true, 'mapped_array' => $mapped, 'rejected_reason_array' => $rejecetd_reason, 'status_update_array' => $status_update_array, ]; } catch (\Throwable $th) { $errorData = [ 'message' => $th->getMessage(), 'file' => $th->getFile(), 'line' => $th->getLine(), 'code' => $th->getCode(), 'trace' => $th->getTraceAsString(), 'trace_array' => $th->getTrace(), // full array version (optional) 'function' => $th->getTrace()[0]['function'] ?? null, 'class' => $th->getTrace()[0]['class'] ?? null, ]; return ['status' => false, "message" => $errorData['message'], 'error_data' => $errorData]; } } public function mapClaimMasterDataOld($file_id): array { $claimDumpFileModel = new ClaimDumpFileModel(); $file_data = $claimDumpFileModel->where('id', $file_id)->first(); $tpaClaimDumpData = $this->db ->table('claims_dump_vidal') ->where('is_active', 1) ->where('file_id', $file_id) ->where('ticket_id IS NULL') ->get() ->getResultArray(); if (empty($tpaClaimDumpData)) { return []; } $ClientPolicyModel = new ClientPolicyModel(); $client_policy_data = $ClientPolicyModel->where('is_active', 1)->findAll(); $mapped = []; $rejecetd_reason = []; foreach ($tpaClaimDumpData as $row) { $item = []; if(isset($row['insurer_policy_number']) && !empty($row['insurer_policy_number'])){ $basic_claim_data = $this->getClientPolicyDataBypolicyNo($client_policy_data, $row['insurer_policy_number']); if(empty($basic_claim_data)){ $reason = " This policy no ( " . $row['insurer_policy_number'] ." ) does not exist in our system"; $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; continue; } $item['client_id'] = $basic_claim_data['client_id'] ?? null; $item['client_policy_id'] = $basic_claim_data['id'] ?? null; $item['insurer_id'] = $basic_claim_data['insurer_id'] ?? null; $item['tpa_id'] = $basic_claim_data['tpa_id'] ?? null; $item['acm_id'] = $basic_claim_data['acm_id'] ?? null; $item['policy_no'] = $basic_claim_data['policy_no'] ?? null; $item['relationship'] = $this->convertRelation($row['relation'] ?? null, $row['gender'] ?? null); $employee_data = $this->getEmployeeDetails($item['client_id'], $item['client_policy_id'], $row['employee_number'], $item['relationship']); if(!empty($employee_data)){ $item['emp_id'] = $employee_data['client_id'] ?? null; $item['emp_name'] = $employee_data['id'] ?? null; $item['emp_mail'] = $employee_data['insurer_id'] ?? null; $item['emp_mobile'] = $employee_data['tpa_id'] ?? null; if (!empty($employee_data['insured_emp_id'])) { $item['insured_emp_id'] = $employee_data['insured_emp_id'] ?? null; $item['insured_name'] = $employee_data['insured_name'] ?? null; }else{ $reason = 'This Dependent employee not exist in our system.'; $rejecetd_reason[] = ["id" => $row['id'], "master_reject_reason" => $reason]; continue; } }else{ $reason = " This policy no ( " . $row['insurer_policy_number'] ." ) does not exist in our system"; $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; continue; } }else{ $reason = " Policy Number is empty"; $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; continue; } foreach ($this->ticketMasterMapping as $tpaKey => $ticketMasterKey) { $item[$ticketMasterKey] = array_key_exists($tpaKey, $row) ? $row[$tpaKey] : null; } $isduplicate = checkDuplicateClaim([ 'doa' => change_date_format($item['doa'] ?? '') ?? null, 'emp_code' => $item['emp_code'] ?? null, 'claim_amount' => $item['claim_amount'] ?? null, 'policy_no' => $item['policy_no'] ?? null ]); if($isduplicate){ $reason = " This claim ( " . $row['insurer_policy_number'] ." ) does not exist in our system"; $rejecetd_reason[$row['id']] = ["ticket_master_insert_reject_reason" => $reason]; continue; } // Meta fields $item['file_id'] = $file_id; $item['claim_dump_date'] = $file_data['claim_dump_date'] ?? null; $item['created_by'] = get_session_userid() ?? null; $item['claim_type'] = isset($row['mainclaim_prepost_type']) && !empty($row['mainclaim_prepost_type']) && strtolower($row['mainclaim_prepost_type']) == 'normal' ? 1 : 3; $item['claim_created_by'] = 'DUMP_TPA'; $mapped[] = $item; } return ['mapped_array' => $mapped, 'rejected_reason_array' => $rejecetd_reason]; } /** * HELPER FUNCTIONs */ public function isDateValue($value): bool { if (empty($value)) { return false; } // Excel numeric date (e.g. 44927) if (is_numeric($value) && $value > 30000) { return true; } // Common date formats return preg_match( '/^\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}$|^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/', (string) $value ) === 1; } public function normalizeDate($value): ?string { try { // Excel numeric date if (is_numeric($value)) { return date('Y-m-d', \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($value)); } // String date return date('Y-m-d', strtotime(str_replace('/', '-', $value))); } catch (\Throwable $e) { return null; } } public function looksLikeDate($value): bool { if (empty($value)) { return false; } // Excel numeric date if (is_numeric($value) && $value > 30000) { return true; } return preg_match( '/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}| \d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}| \d{1,2}\s?[A-Za-z]{3,}\s?\d{2,4}| \d{8}/x', (string) $value ) === 1; } public function convertRelation(?string $relation, ?string $gender = null): ?string { if (empty($relation)) { return null; } $relation = strtolower($relation); $gender = strtolower((string) ($gender ?? '')); if ($relation == 'self') { return $relation; } if ($relation == 'spouse') { return $relation; } if ($relation == 'child' && $gender == 'male') { return 'son'; } if ($relation == 'child' && $gender == 'female') { return 'daughter'; } if ($relation == 'parents' && $gender == 'male') { return 'father'; } if ($relation == 'parents' && $gender == 'female') { return 'mother'; } if ($relation == 'parents-in-law' && $gender == 'male') { return 'father-in-law'; } if ($relation == 'parents-in-law' && $gender == 'female') { return 'mother-in-law'; } return null; } public function getClientPolicyDataBypolicyNo(array $client_policy_data, string $policy_number): array { $matched_data = []; foreach ($client_policy_data as $key => $value) { if(trim($value) == trim($policy_number)){ $matched_data = $value; } } if(!empty($matched_data)){ $ClientRMModel = new ClientRMModel(); $acm_data = $ClientRMModel->where('is_active', 1)->where('level', 3)->where('client_id', $matched_data['client_id'])->orderBy('id', 'asc')->first(); if(!empty($acm_data)){ $matched_data['acm_id'] = $acm_data['id'] ?? null; } } return $matched_data; } }