} else {
    //query for inserting referring_in in doctor_stub
    $temp = "temp";
    $visibility = 1;
    $insert_pending_referring_in = mysql_query("insert into doctor_stub (Doctor_Title,Doctor_name,Doctor_mobile_number,visibility,Doctor_unregistered) values('{$doctor_title}','{$name}','{$mobile}','{$visibility}','{$temp}')");
}
if ($doctor_id != "") {
    $doctor_stub_id = $doctor_id;
}
$refering_in_query = mysql_query("INSERT INTO hospital_refer_in_doctor_stub(refer_in_doc_title,refer_in_doc_name, refer_in_doc_mobile,refer_in_doc_email,refer_by_hos_id,doc_stub_id) VALUES ('{$doctor_title}','{$name}','{$mobile}','{$email}','{$hospital_id}','{$doctor_stub_id}')");
//query to get the helper clarification table
$getClarificationHelper = mysql_query("select * from clarification_member_by_hospital where hospital_id='{$hospital_id}'");
$row_helper = mysql_fetch_assoc($getClarificationHelper);
$person = $row_helper['person_name'];
$mobile_number = $row_helper['mobile_number'];
$extra_notes = $row_helper['extra_notes'];
$clarification_msg = "For any help, contact " . $person . " at " . $mobile_number . ".Thanks." . $Doctor_HospitalName . "." . $extra_notes;
$mobile_txt_msg = $Doctor_HospitalName . ": Dear " . $doctor_title . $name . " You have been added as a Referring doctor by " . $Doctor_HospitalName . ". Please use this below link to download the app: " . $link . "  Or you can search for Referralio on android or ios app store";
send_msg($mobile, $mobile_txt_msg);
if ($email != '') {
    $email_sender->send_email($email, $mobile_txt_msg);
}
if ($refering_in_query == "success") {
    send_msg($mobile, $clarification_msg);
    $success = array('status' => "Success", "msg" => "Successfully Registered");
} else {
    $success = array('status' => "Failure", "msg" => "Refer In doctor could not be registered");
}
echo json_encode($success);
exit(0);
function send_msg($mobile, $mobile_msg)
        //do nothing
    }
} else {
    //do nothing for the time being
}
//end of changes for referral map entry
if ($sql_insert) {
    //for sending text message to patient
    $logger->write("INFO :", "inside success");
    $msg_pat_txt = $hospital_name . " :- You have been referred to " . $doc_ref_title . $doc_ref_id_name . " by " . $doc_title . $doctor_name;
    //send_msg($pat_mobile,$msg_pat_txt);//commented as per requested
    //for sending text message to referred doctor
    $msg_doc_txt = $hospital_name . " - Patient " . $pat_name . " has been referred to you by " . $doc_title . $doctor_name;
    send_msg($doc_ref_mobile_number, $msg_doc_txt);
    if ($doc_ref_email != '') {
        $email_sender->send_email($doc_ref_email, $msg_doc_txt);
    }
    //for sending text message to referring doctor
    $msg_doc_txt = $hospital_name . " - Dear " . $doc_title . $doctor_name . ", Thank you for referring Patient " . $pat_name;
    //.".You can get real time updates of this patient by downloading Referralio app on your phone";
    send_msg($doc_mob_number, $msg_doc_txt);
    if ($doc_email != '') {
        $email_sender->send_email($doc_email, $msg_doc_txt);
    }
    $registatoin_ids = array($gcm_id);
    $message = array("msg" => " " . $hospital_name . " - " . $doc_ref_title . $doc_ref_id_name . " has reffered a patient " . $pat_name, "flag_push" => "Refer", "Refer_In_cnt" => $cnt_refer_in);
    $result = $gcm->send_notification($registatoin_ids, $message);
    $success = array('status' => "Success", "msg" => "Patient successfully registered", "result" => $result);
    echo json_encode($success);
} else {
    $success = array('status' => "Failure", "msg" => "Transaction Could not be registered", "result" => $result);
$reg_email = $row_pat_referring['Reg_email'];
$pat_name = $row_pat_referring['Patient_Name'];
$ref_mob_number = $row_pat_referring['Ref_mob_number'];
$ref_title = $row_pat_referring['Ref_Title'];
$ref_name = $row_pat_referring['Ref_name'];
$ref_email = $row_pat_referring['Ref_email'];
//end of getting data
$sms_msg_referring_doc = $hospital_name . " - Dear " . $reg_title . $reg_name . ", current status for patient " . $pat_name . " : " . $status;
$sms_msg_referred_doc = $hospital_name . " - Dear " . $ref_title . $ref_name . ", current status for patient " . $pat_name . " : " . $status;
$update_status = "update patient_stub set secondary_status='{$status}' where Patient_thread_id='{$pat_id}'";
$result = mysql_query($update_status);
if ($result) {
    send_msg($reg_mob_number, $sms_msg_referring_doc);
    send_msg($ref_mob_number, $sms_msg_referred_doc);
    if ($reg_email != '') {
        $email_sender->send_email($reg_email, $sms_msg_referring_doc);
    }
    if ($ref_email != '') {
        $email_sender->send_email($ref_email, $sms_msg_referred_doc);
    }
    $success = array('status' => "Success", "msg" => "Patient status updated successfully");
    echo json_encode($success);
} else {
    $success = array('status' => "Failure", "msg" => "Patient status could not be updated");
    echo json_encode($success);
}
function send_msg($mobile, $mobile_msg)
{
    //$logger->write("INFO :","login with mobile".$mobile);
    $msg = "";
    $msg = urlencode($mobile_msg);
             $res_sql_mob = mysql_fetch_assoc($sql_mob_unique_temp);
             $doc_ser_id = $res_sql_mob['Doctor_serial_id'];
             $update_doctor = mysql_query("update doctor_stub set Doctor_name='{$Doctor_name}',Doctor_dob='{$Doctor_dob}',Doctor_email='{$Doctor_email}',Doctor_specialization='{$Doctor_specialization}',Doctor_qualification='{$Doctor_qualification}',Doctor_HospitalName='{$Doctor_HospitalName}',Doctor_Country='{$Doctor_Country}',Doctor_State='{$Doctor_State}',Doctor_City='{$Doctor_City}',Doctor_Address='{$Doctor_Address}',Doctor_password=md5('{$Doctor_password}'),Doctor_photograph='{$imageName}',Doctor_yxp='{$Doctor_yxp}',license_number='{$license_number}',visibility='{$visibility}',my_type='{$my_type}',country_code='{$country_code}',Doctor_unregistered='{$doc_unregister}' where Doctor_mobile_number='{$Doctor_mobile_number}'");
             $update_refer_in = mysql_query("update hospital_refer_in_doctor_stub set doc_stub_id='{$doc_ser_id}' where refer_in_doc_mobile='{$Doctor_mobile_number}'");
             $logger->write("INFO :", "updated doctor stub with doc info and hospital_refer_in_doctor_stub with doc serial id");
             //$success = array('status' => "Success", "msg" => "Successfully doctor has been registered");
             //$this->response($this->json($success),200);
         }
         //sending text message to registered doctor_id_present
         $link = "https://play.google.com/store/apps/details?id=com.hospitalcheck.referralio&hl=en";
         $mobile_txt_msg = $hospital_name . " - Dear " . $doctor_title . $Doctor_name . " You have been added as a inhouse doctor by " . $Doctor_HospitalName . " hospital.Please use this below link to download the app: " . $link;
         //$logger->write("calling mobile msg");
         send_msg($Doctor_mobile_number, $mobile_txt_msg);
         //sending email if doctor email is present
         if ($Doctor_email != '') {
             $email_sender->send_email($Doctor_email, $mobile_txt_msg);
         }
         $success = array('status' => "Success", "msg" => "Successfully doctor has been registered");
         //$this->response($this->json($success),200);
         echo json_encode($success);
         exit(0);
     } else {
         $success = array('status' => "Failure", "msg" => "Doctor already added in this hospital");
         //$this->response($this->json($success),200);
         echo json_encode($success);
         exit(0);
     }
 } else {
     $success = array('status' => "Failed", "msg" => "Doctor already added as a hospital doctor in another hospital");
     //$this->response($this->json($error), 400);
     echo json_encode($success);