$(document).ready(function () {
    $('#fileuploadmodel').hide();
    $('#Btn_AddFileUP').show();
    $('#Btn_editFileUP').hide();
})
$('#txtPaitentSearch_workorder').autocomplete({
    source: function (request, response) {
        $.ajax({
            async: true,
            //url: "/PatientSearch/AutoCompleteData?PName=" + $('#txtPaitentSearch_workorder').val(),
            url: "/PatientSearch/AutoCompleteData?PName=" + $('#txtPaitentSearch_workorder').val() + '&role=' + $('#hiddenRole_id').val(),
            type: "POST",
            dataType: "json",
            data: { Prefix: request.term, branch_id: $('#HospitalBranchID').val(), Dml_Indicator: 'AOS' },
            success: function (data) {
                debugger;
                console.log(data);
                if (data.length == 0 ) {
                    $('#PtxtPaitentSearch_workorder').show();
                    $('#PtxtPaitentSearch_workorder').fadeOut(8000);
                    $('#PtxtPaitentSearch_workorder').html('"No Patient Found"');
                    $('#txtPaitentSearch_workorder').focus();
                    response([{ label: 'No results found.', value: -1 }]);
                    return false;
                }
                else {
                    response($.map(data, function (item) {

                        console.log('------>' + item.address_line_1);
                        return { label: item.patient_first_name + '/' + item.Patient_id + '/' + item.phone_number_1 + '/' + item.phone_number_2, value: item.SearchOption, name: item.patient_first_name, ageval: item.age, patientid: item.Patient_id, mobileno: item.phone_number_1, mobileno1: item.phone_number_2, doctor_patient_id: item.doctor_patient_id, father_name: item.father_name, is_deleted: item.is_deleted };
                        // $('#showlist').click();
                    }))
                }
             
            }
        })
    },
    minLength: 1,
    select: function (event, ui) {
        $('#hndpatientid').val(ui.item.patientid)
       loadexternallabworkorder(ui.item.patientid)
    },
    html: true,
    open: function (event, ui) {
        $(".ui-autocomplete").css("z-index", 1000);
    }
})


function loadexternallabworkorder(patientid) {
    debugger;
    var servicevalues = {
        Dml_Indicator: "WOSL",
        servicename: patientid,   
        spname: "SP_Work_Order_OutSource_lab",
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Workorder/Get_Workorder',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(servicevalues),
        success: function (data) {
            debugger;

            var data = JSON.parse(data);
            console.log(data);
            if (data.msg == "Success") {
                var data1 = data.data;
                if (jQuery.isEmptyObject((data1))) {
                    tr = '';
                    $('#outsourceworkordertbody').html(tr);
                }
                else {

                    var b = data1.Table;
                    $('#outsourceworkordertbody').empty();
                    $('#outsourceworkordertable').dataTable().fnClearTable();
                    //$('#outsourceworkordertable').dataTable().fnDraw();
                    $('#outsourceworkordertable').dataTable().fnDestroy();
                    tr = '';
                    var popupflagid = '', popupflag = '', onclickflag = '', sflg = '', deleteflag = '', Upload='',getservice='';

                    $.each(b, function (i, emp) {

                        if (emp.wid == null) {
                            getservice = '<a id="ldtservice_name_' + i + '" value=' + emp.master_service_id + ' data-id=' + emp.master_service_id + ' data1-id=' + emp.is_lab + '>' + '<span class="tbl-name">' + emp.service_name + '</span><Span class="tbl_wpkg"><br>' + (($.trim(emp.package_name) != '') ? emp.package_name + ' / ' + emp.package_id : emp.package_id) + '</span></a>';
                        }
                        else{
                           getservice = '<a class="details-control" ' + sflg + ' onclick=servicedetailsOS(this,"' + emp.work_order_id + '","' + emp.wid + '",' + emp.package_id + ');>' + emp.service_count + '<Span class="tbl_wpkg"><br>' + (($.trim(emp.package_name) != '') ? emp.package_name + ' / ' + emp.package_id : emp.package_id) + '</span><i class="fa fa-angle-double-down table-arrow-size pull-right"></i></a>';
                          }
                         
                      
                        Upload = '<a data-toggle="tooltip" title="File Upload" class="btn btn-edit btn-xs" data-id="" data-type="" data-nav="sp_div" data-name="c_details_form"  href="javascript:void(0);" onclick=GetFileUpload("' + emp.work_order_id + '")><i class="fa fa-upload" aria-hidden="true"></i></a>';

                        tr = tr + '<tr id="t_' + emp.work_order_id + '"><td>' + emp.patient_username + '<Span class="tbl_pno"><br>' + emp.patient_id + '</span></td><td>' + emp.phone_number_1 + '</td><td>' + emp.doctorname + '</td><td>' + getservice + '</td><td>' + emp.work_order_no + '</td><td>' + Upload + '</td></tr>';

                    });

                    $('#outsourceworkordertbody').html(tr);

                    datatable('outsourceworkordertable');

                }
            }
        }
    });
}
//Show/hide service subtable
function servicedetailsOS(e, id, wid, pkid) {
    // alert('test')
    debugger;
    var tr = e.closest('tr');

    var row = $('#outsourceworkordertable').DataTable().row(tr);
  
   
    console.log(row);
    //var row = $('#request_view').DataTable().row(tr);

    if (row.child.isShown()) {
        // This row is already open - close it
        row.child.hide();
        // tr.removeClass('shown');
    }
    else {
        // Open this row
        row.child(servicedetailspackageoutsource(event, id, wid, pkid)).show();
        //  tr.addClass('shown');
    }
        
}
//getting service details for subtable
function servicedetailspackageoutsource(event,id, wid, pkid) {
    debugger;
    div = $('<div/>')
        .addClass('loading')
        .addClass('table_child')
        .addClass('table-responsive');
    var service_data = {
        work_orderid: id,
        //flag: wtype,
        //jobsflag: jobsflag,
        //barcodeid: (pkid=='') ? 0 : pkid,
        samplbarcodeid: wid,
        //serviceproviderid: spid,
        Dml_Indicator: 'SDP',
        spname: "SP_Work_Order_Action",
        //work_order_status: (work_order_status=='') ? 0 : work_order_status ,
        //scheduledate: (patientpreferdate == undefined) ? 0 : patientpreferdate,
        //departmentid: departmentideader
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Workorder/Get_Workorder',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(service_data),
        success: function (data) {
            debugger;
            var data = JSON.parse(data);
            console.log(data);
            if (data.msg == "Success") {
                var data1 = data.data;
                var tr = '', j = 1;

                if (jQuery.isEmptyObject((data1))) {
                }

                else {
                    div.removeClass('loading')

                    var row = 2;
                    var tr, row_data;
                    tr = $('<table class="table table-bordered table-hover dt-responsive">');

                        tr.append('<thead><tr class="info"><th>S.No</th><th>Service Code</th><th>Service Name</th><th>Number of Usage</th></tr></thead><tbody>');
                        $.each(data1.Table, function (i, emp) {
                            row_data = '<tr id="t_' + emp.work_order_details_id + '"><td>' + j + '</td><td>' + emp.service_code + '</td><td>' + emp.service_name + '</td><td>' + emp.quantity + '</td></tr>';
                            j = j + 1;
                            tr.append(row_data);
                        })
                    
                    tr.append("</tbody>");

                    div.append(tr);

                }
            }
            else {
                console.log(data);
            }
        }
    });
    return div;
}



//File Uplaod Start

//function OutSourceLabfileupload(id) {
//    debugger;
//    var UploadFileid = id;
//    var photo = id + '_photo';
//    var pathvalue = id + '_pathvalue';

//    var uploadpath = $('#' + id).val();
//    var fileExtension = uploadpath.substring(uploadpath.lastIndexOf(".") + 1, uploadpath.length);
//    if (window.FormData !== undefined) {
//        var fileUpload = $('#' + id).get(0);
//        var files = fileUpload.files;
//        var fileData = new FormData();

//        //var filePath = fileUpload.value;
//        var allowedExtensions =
//           /(\mp4|\m4v|\mov)$/i;
//        //if (!allowedExtensions.exec(filePath)) {
//        if (fileExtension.match(allowedExtensions)) {
//            //if (allowedExtensions == /(\.mp4|\.m4v|\.mov)$/i) {

//            for (var i = 0; i < files.length; i++) {
//                fileData.append(files[i].name, files[i]);
//            }

//            fileData.append('username', 'Manas');
//            $.ajax({
//                url: '/Workorder/UploadOutSourceLabFiles',
//                type: "POST",
//                contentType: false,
//                processData: false,
//                data: fileData,
//                success: function (result) {
//                    $.each(result, function (i, emp) {

//                        $('#' + photo).empty();
//                        $('#' + photo).show();
//                        $('#' + pathvalue).val(emp);
//                        $('#' + photo).append('<a href="' + $('#hdnHospitalfilepath').val() + "/OutSourceLabFileUpload/" + emp + '" target="_blank">' + UploadFileid + '</a>');
//                    });
//                }
//            });
//        }

//        else {

//            var allowedExtensions =
//               /(\.jpg|\.jpeg|\.png)$/i;

//            $.when(checkimagedimensionvalidation(fileUpload.files[0], 512, 512)).
//        done(function (Results) {

//            if (Results == 'Success') {
//                for (var i = 0; i < files.length; i++) {
//                    fileData.append(files[i].name, files[i]);
//                }

//                fileData.append('username', 'Manas');
//                $.ajax({
//                    url: '/Workorder/UploadOutSourceLabFiles',
//                    type: "POST",
//                    contentType: false,
//                    processData: false,
//                    data: fileData,
//                    success: function (result) {
//                        $.each(result, function (i, emp) {

//                            $('#' + photo).empty();
//                            $('#' + photo).show();
//                            $('#' + pathvalue).val(emp);
//                            $('#' + photo).append('<a href="' + $('#hdnHospitalfilepath').val() + $('#HospitalId').val()+ "/OutSourceLabFileUpload/" + emp + '" target="_blank">' + UploadFileid + '</a>');
//                        });
//                    }
//                });
//            }
//            else {
//                $('#OutSource_File').val('');
//                $('#' + photo).empty();
//            }
//        });
//        }
//    }
//}

function OutSourceLabfileupload(id) {
    var UploadFileid = id;
    var photo = id + '_photo';
    var pathvalue = id + '_pathvalue';

    var fileUpload = $('#' + id).get(0);
    var files = fileUpload.files;
    var fileData = new FormData();

    for (var i = 0; i < files.length; i++) {
        fileData.append('files', files[i]);
    }

    fileData.append('username', 'Manas');

    $.ajax({
        url: '/Workorder/UploadOutSourceLabFiles',
        type: "POST",
        contentType: false,
        processData: false,
        data: fileData,
        success: function (result) {
            $.each(result, function (i, emp) {
                $('#' + photo).empty();
                $('#' + photo).show();
                $('#' + pathvalue).val(emp);
                $('#' + photo).append('<a href="' + $('#hdnHospitalfilepath').val() + $('#HospitalId').val() + "/OutSourceLabFileUpload/" + emp + '" target="_blank">' + UploadFileid + '</a>');
            });
        }
    });
}


function GetFileUpload(workOrderId) {
    debugger;
    $('#hndworkOrderId').val(workOrderId)
    $('#fileuploadmodel').show();
    var servicevalues = {
        Dml_Indicator: "OSL",
        work_orderid: workOrderId,
        spname: "SP_Work_Order_OutSource_lab",
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Workorder/Get_Workorder',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(servicevalues),
        success: function (data) {
            debugger;

            var data = JSON.parse(data);
            console.log(data);
            if (data.msg == "Success") {
                var data1 = data.data;
                if (jQuery.isEmptyObject((data1))) {
                    tr = '';

                }
                else {

                    var b = data1.Table;
                    $('#outsourcelab_tbody').empty();
                    $('#outsourcelab_tbl').dataTable().fnClearTable();
                    $('#outsourcelab_tbl').dataTable().fnDraw();
                    $('#outsourcelab_tbl').dataTable().fnDestroy();
                    tr = '';
                    var fileCounter = 1;
                    for (var i = 0; i < b.length; i++) {
                        var rowData = b[i];
                        var File_path = '<a href="' + $('#hdnHospitalfilepath').val() + $('#HospitalId').val() + "/OutSourceLabFileUpload/" + rowData.document_path + '" target="_blank"  id="document_path_' + rowData.outsourcelabid + '">OutSourceLab_Image</a>';
                        var newRow = "<tr data-fileid='" + rowData.outsourcelabid + "'>" +
                            "<td>" + fileCounter + "</td>" +
                            "<td>" + File_path + "</td>" +
                             "<td>" +
                                '<a data-toggle="tooltip" title="Edit" data-id="SM_D1" data-type="role_rights_edit" data-nav="sp_delete" data-name="c_details_form" href="javascript:void(0);" class="btn btn-edit btn-xs btn-add" onclick="FilePathEdit(this,\'' + rowData.outsourcelabid + '\')" data-id=' + rowData.outsourcelabid + '><i class="fa fa-pencil" aria-hidden="true"></i></a>' +
                                '<a data-toggle="tooltip" title="Delete" data-id="SM_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" href="javascript:void(0);" class="btn btn-delete btn-xs" onclick="FilePathDelete(this,\'' + rowData.outsourcelabid + '\')"><i class="fa fa-trash-o" aria-hidden="true"></i></a>' +
                            "</td>" +
                            "<td><input type='hidden' class='outsourceid_' value='" + rowData.outsourcelabid + "' /></td>" +
                            "<td><input type='hidden' class='file-path' value='" + rowData.document_path + "' /></td>" +
                            "</tr>";
                        $("#outsourcelab_tbody").append(newRow);
                        // fileCounter = rowData.outsourcelabid + 1; // Update the file counter
                        fileCounter++;
                    }

                }
            }
        }
    });
}


$('#Btn_AddFileUP').click(function () {
    debugger;
    $('#OutSource_File_photo').empty();

    if ($('#OutSource_File_pathvalue').val() == "") {
        $('#POS_documents').show();
        $('#POS_documents').fadeOut(8000);
        $('#POS_documents').html('Please Upload File');
        $('#POS_documents').focus();
        $('#OutSource_File_pathvalue').val('');
        return false;
    }

    var fileName = $('#OutSource_File_pathvalue').val();
    // var fileName = fileInput.val().split('\\').pop(); // Extract file name
    if (fileName) {
        var fileCounter = $("#outsourcelab_tbody tr").length + 1;
        var outsourceid = 0;
        var lastRow = $("#outsourcelab_tbody tr:last");
        if (lastRow.length > 0) {
            outsourceid = lastRow.find(".outsourceid_").val();
        }
        // Add file to the table temporarily
        //   File_path = '<a href="' + $('#hdnHospitalfilepath').val() + "OutSourceLabFileUpload/" + FilePath + '" target="_blank" id="tdFilePathval_' + rowcount + '">OutSourceLab_Image</a>';
        var File_path = '<a href="' + $('#hdnHospitalfilepath').val() + $('#HospitalId').val() + "/OutSourceLabFileUpload/" + fileName + '" target="_blank"  id="tdFilePathval_' + fileCounter + '">OutSourceLab_Image</a>';
        var newRow = "<tr data-fileid='" + fileCounter + "'>" +
            "<td>" + fileCounter + "</td>" +
            "<td>" + File_path + "</td>" +
             "<td class='disp_if'>" +
                "<button class='btn-xs btn btn-edit btn-add update_edit_Sno' onclick='TempFilePathEdit(" + fileCounter + ")' data-id=" + fileCounter + "><i class='fa fa-pencil' aria-hidden='true'></i></button>" +
                "<button class='btn-xs btn btn-delete btn-add update_delete_Sno' onclick='TempFilePathDelete(" + fileCounter + ")'><i class='fa fa-trash-o' aria-hidden='true'></i></button>" +
            "</td>" +
            "<td><input type='hidden' class='outsourceid_' value='" + 0 + "' /></td>" +
            "<td><input type='hidden' class='file-path' value='" + fileName + "' /></td>" +
            "</tr>";
        $("#outsourcelab_tbody").append(newRow);

        $('#OutSource_File').val('');
        $('#OutSource_File_pathvalue').val('');
        $('#OutSource_File_photo').empty();
    }
});

$('#Savefiles').click(function () {
    debugger;
    var customers = new Array();

    var tot_rowM = $('#outsourcelab_tbl >tbody >tr').length;
    if (tot_rowM > 0) {
        var L = 0, M = 0;
        for (j = 0; j <= tot_rowM - 1; j++) {
            var OutSourcevalues = {};
            var chkfilePath = $('#outsourcelab_tbl >tbody >tr:eq(' + j + ') .file-path').val();

            if (chkfilePath != '') {
                var outsourcelabid = 0, filePath = '';
               
                var outsourcelabid = $('#outsourcelab_tbl >tbody >tr:eq(' + j + ') .outsourceid_').val();
                var filePath = $('#outsourcelab_tbl >tbody >tr:eq(' + j + ') .file-path').val();

                OutSourcevalues.document_path = filePath;
                OutSourcevalues.work_orderid = $('#hndworkOrderId').val();
                OutSourcevalues.outsourcelabid = outsourcelabid;
                OutSourcevalues.Dml_Indicator = "OSI";
                OutSourcevalues.spname = "SP_Work_Order_OutSource_lab",
                OutSourcevalues.created_by = $('#hiddenUser_id').val();
                customers.push(OutSourcevalues);
            }
        }
    }
    else {
        toastr.warning("Please Upload Any One Of The  Files");
        return;
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Workorder/OutSourceLab',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(customers),
        success: function (data) {
            debugger;
            var data = JSON.parse(data);
            console.log(data);
            if (data.msg == "Success") {
                var data1 = data.data;
                if (jQuery.isEmptyObject((data1))) {

                }
                else {
                    if (data1.Table[0].status == "Success") {
                        toastr.success('Saved Successfully');
                        //$('#outsourcelab_tbl >tbody >tr').remove();
                        GetFileUpload($('#hndworkOrderId').val())

                    }

                }
            }
        }
    })

})
function TempFilePathDelete(val) {
    debugger;
    var deletedRow = $("#outsourcelab_tbody").find("tr:eq(" + (val - 1) + ")");
    deletedRow.remove();
    toastr.success("Removed Successfully");

    // Update serial numbers
    updateSerialNumbers();
}
function updateSerialNumbers() {
    debugger;
    // Get all rows in the table body
    var rows = $("#outsourcelab_tbody").find("tr");

    // Update serial numbers based on the data-fileid attribute
    rows.each(function (index, row) {
        var newFileId = index + 1;

        // Update data-fileid attribute
        $(row).attr('data-fileid', newFileId);

        // Update the first column (serial number)
        $(row).find('td:first').text(newFileId);

        // Update the data-id attribute in the buttons
        $(row).find('.update_edit_Sno').attr('data-id', newFileId);
        $(row).find('.update_delete_Sno').attr('data-id', newFileId);

        // Update the onclick attribute for the buttons
        $(row).find('.update_edit_Sno').attr('onclick', 'TempFilePathEdit(' + newFileId + ')');
        $(row).find('.update_delete_Sno').attr('onclick', 'TempFilePathDelete(' + newFileId + ')');

        // Update the ID of the link
        var tdFilePathvalId = 'tdFilePathval_' + newFileId;
        $(row).find('a[id^="tdFilePathval_"]').attr('id', tdFilePathvalId);

    });
}

function FilePathDelete(event, val) {
    debugger;
    var did = $(event).attr("data-id");
    var navigation = $(event).attr("data-nav");
    var name = $(event).attr("data-name");
    var columntype = $(event).attr("data-type");
    debugger;
    var chkprevilige = check_previlige(did, navigation, name, columntype);
    $.when(chkprevilige)
     .then(function (data) {
         var data1 = JSON.parse(data);
         if (data1.msg == "Success") {
             var data1 = data1.data;
             if (jQuery.isEmptyObject((data1))) {
             }
             else {
                 var j = 0;
                 var status = data1.Table[0].role_rights_add
                 if (status == 0) {

                     return;
                 }
                 else {
                     toastr.warning("<button type='button' id='confirmationRevertYes' class='btn btn-warning btn-xs mt20'>Yes</button><button type='button' id='confirmationRevertNo' class='btn btn-warning btn-xs mt20'>No</button>", 'Are You Sure,You want to Delete the File?',
      {

          closeButton: true,
          progressBar: true,
          allowHtml: true,
          timeOut: 20000000,

          onShown: function (toast) {
              $("#confirmationRevertYes").click(function () {
                  debugger;
                  var servicevalues = {
                      Dml_Indicator: "OSDEL",
                      work_orderid: val,
                      spname: "SP_Work_Order_OutSource_lab"
                  }
                  $.ajax({
                      async: true,
                      type: 'POST',
                      url: '/Workorder/Get_Workorder',
                      contentType: 'application/json; charset=UTF-8',
                      data: JSON.stringify(servicevalues),
                      success: function (data) {


                          var data2 = JSON.parse(data);
                          console.log(data2)
                          if (jQuery.isEmptyObject((data2))) {

                          }
                          else {
                              if (data2.msg == "Success") {
                                  debugger;
                                  $(event).closest('tr').remove();
                                  updateSerialNumbers(); // Update serial numbers after deletion
                                  toastr.success("Deleted Successfully");
                              }
                          }
                      }
                  });



              });
          }
      });
                 }
             }
         }
     });
}
function TempFilePathEdit(val) {
    debugger;
    //var tdFilePath = $('#tdFilePath_' + val).val()
    var tdFilePath = $("#outsourcelab_tbody").find("tr[data-fileid='" + val + "']").find(".file-path").val();
    var FileTypeName = $('#tdFileTypeName_' + val).val();

    if (tdFilePath != null && tdFilePath != "") {
        $('#OutSource_File_photo').empty();
        $('#OutSource_File_photo').show();
        $('#OutSource_File_photo').append('<a href="' + $('#hdnHospitalfilepath').val() + $('#HospitalId').val() + "/OutSourceLabFileUpload/" + tdFilePath + '" target="_blank">"' + tdFilePath + '"</a>');
        $('#OutSource_File_pathvalue').val(tdFilePath);
    }

    $('#Hdnrowid').val(val);

    $('#Btn_AddFileUP').hide();
    $('#Btn_editFileUP').show();
}
function FilePathEdit(event, val) {
    debugger;
    var did = $(event).attr("data-id");
    var navigation = $(event).attr("data-nav");
    var name = $(event).attr("data-name");
    var columntype = $(event).attr("data-type");
    debugger;
    var chkprevilige = check_previlige(did, navigation, name, columntype);
    $.when(chkprevilige)
     .then(function (data) {
         var data1 = JSON.parse(data);
         if (data1.msg == "Success") {
             var data1 = data1.data;
             if (jQuery.isEmptyObject((data1))) {
             }
             else {
                 var j = 0;
                 var status = data1.Table[0].role_rights_add
                 if (status == 0) {

                     return;
                 }
                 else {
                     debugger;
                     //var tdFilePath = $('#hndocument_path_' + val).html();
                     var tdFilePath = $(event).closest('tr').find('.file-path').val();

                     if (tdFilePath != null && tdFilePath != "") {
                         $('#OutSource_File_photo').empty();
                         $('#OutSource_File_photo').show();
                         $('#OutSource_File_photo').append('<a href="' + $('#hdnHospitalfilepath').val() + $('#HospitalId').val() + "/OutSourceLabFileUpload/" + tdFilePath + '" target="_blank">"' + tdFilePath + '"</a>');
                         $('#OutSource_File_pathvalue').val(tdFilePath);
                     }

                     $('#Hdnrowid').val(val);

                     $('#Btn_AddFileUP').hide();
                     $('#Btn_editFileUP').show();
                 }
             }
         }
     });

}
$('#Btn_editFileUP').click(function () {
    debugger;
    var FilePath = $('#OutSource_File_pathvalue').val();

    if ($('#OutSource_File_pathvalue').val() == '') {
        $('#POS_documents').show();
        $('#POS_documents').fadeOut(8000);
        $('#POS_documents').html('Choose File');
        $('#OutSource_File_pathvalue').val('');
        $('#OutSource_File_pathvalue').focus();
        return false;
    }

    var rowid = $('#Hdnrowid').val();
  
    var tr = $("#outsourcelab_tbody").find("tr[data-fileid='" + rowid + "']");

 
    //temp
    $('#tdFilePathval_' + rowid).empty().html('<a href="' + $('#hdnHospitalfilepath').val() + $('#HospitalId').val() + '/OutSourceLabFileUpload/' + FilePath + '" target="_blank">OutSourceLab_Image</a>');
     //org
    $('#document_path_' + rowid).empty().html('<a href="' + $('#hdnHospitalfilepath').val() + $('#HospitalId').val() + '/OutSourceLabFileUpload/' + FilePath + '" target="_blank">OutSourceLab_Image</a>');


    $('#outsourcelab_tbody').find("tr[data-fileid='" + rowid + "']").find('.file-path').val(FilePath);

    $('#Btn_AddFileUP').show();
    $('#Btn_editFileUP').hide();
    $('#OutSource_File_pathvalue').val('');
    $('#OutSource_File').val('');
    $('#OutSource_File_photo').empty();
    $('#Hdnrowid').val('');

});