@include('header')
@php
$UserId = Session::get('UserId');
@endphp
<div class="container-fluid flex-grow-1 container-p-y">
    <div class="row">
        <!-- customar project  start -->
        <div class="col-xl-12">
            <div class="card">
                <div class="card-body">

                    <form id="validation-form2" novalidate="novalidate" method="POST" enctype="multipart/form-data"
                        autocomplete="off" action="" name="myForm" onsubmit="return validation(this);">
                        <input type="hidden" name="action" value="SaveOldQueue">

                        @csrf
                        
                        <div class="form-row">
                            <div class="form-group col-md-1 showoldfields" style="display:block;">
                                <label class="floating-label" for="Name">Mrd No <span
                                        class="text-danger">*</span></label>
                                <input type="text" id="MRD_NO" name="MRD_NO" class="form-control" value="" oninput="getPatientVal()">
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-2 showoldfields" style="display:block;">
                                <label class="floating-label" for="Name">Patient Name </label>
                                <input type="text" id="PatientName" name="PatientName" class="form-control"
                                    placeholder="" disabled>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-1 showoldfields" style="display:block;">
                                <label class="floating-label" for="Name">Age </label>
                                <input type="text" id="PatientAge" name="PatientAge" class="form-control" placeholder=""
                                disabled>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-1 showoldfields" style="display:block;">
                                <label class="floating-label" for="gender">Gender </label>
                                <select class="form-control" id="PatGender" name="PatGender" disabled>
                                    <option value="" disabled="" selected="">Select Gender</option>
                                    <option value="Male">Male</option>
                                    <option value="Female">Female</option>
                                </select>
                            </div>


                            


                           


                            <div class="form-group col-md-2 showoldfields" style="display:block;">
                                <label class="floating-label" for="Name">Address <span
                                        class="text-danger">*</span></label>
                                <input type="text" id="PatientAddress" name="PatientAddress" class="form-control"
                                    placeholder="" disabled>
                                <div class="clearfix"></div>
                            </div>
                            <!-- <div class="form-group col-md-2 showoldfields" style="display:block;">
                                <label class="floating-label" for="Name">City <span class="text-danger">*</span></label>
                                <input type="text" id="PatientCity" name="PatientCity" class="form-control"
                                    placeholder="" disabled>
                                <div class="clearfix"></div>
                            </div> -->

                            <div class="form-group col-md-4 showoldfields" style="display:block;padding-top:20px;">
                                <button type="button" id="submit" class="btn btn-primary btn-finish" onclick="viewOpdDetails()" disabled>View Report</button>
                                <!-- <button type="button" id="submit2" class="btn btn-success btn-finish" onclick="viewOtNotes()" disabled>View OT Notes</button> -->
                            </div>
                            
                        </div>

                    <input type="hidden" id="visitno">
                    </form>
                    
                </div>
            </div>
        </div>
        <!-- customar project  end -->
    </div>
</div>


@include('footerscript')
<script>
    function viewOpdDetails(){
        var mrdno = $('#MRD_NO').val();
        var visitno = $('#visitno').val();
        setTimeout(function() {
            window.open(
                '/{{projectUrl()}}opdSummary/' + mrdno, 'popUpWindow2',
                'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }

    function viewOtNotes(){
        var mrdno = $('#MRD_NO').val();
        setTimeout(function() {
            window.open(
                '/{{projectUrl()}}opdOtNotesReport/' + mrdno, 'popUpWindow3',
                'height=1000,width=1500,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }
    function getPatientVal() {
   var val = $('#MRD_NO').val();
    $.ajax({
        url: "{{ url('getPatientDetails') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            id: val
        },
        dataType: "json",
        success: function(data) {
            //console.log(data);
            $('#MRD_NO').val(data.MrdNo);
            $('#PatientName').val(data.PatientName);
            $('#PatientAge').val(data.Age);
            $('#PatGender').val(data.Gender).attr("selected", "selected");
            $('#PatientAddress').val(data.Address);
            $('#PatientCity').val(data.City);
            //$('#PartStateId').html(data);
            //findCurrAge(data.MrdNo);
            $('#submit').attr('disabled',false);
            $('#submit2').attr('disabled',false);
            getLastVisit(data.MrdNo);
        }
    });
}

function getLastVisit(mrdno){
    $.ajax({
        url: "{{ url('getLastVisit') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            mrdno: mrdno
        },
        success: function(data) {
            $('#visitno').val(data);
        }
    });
}

$(document).ready(function() {
$(document).on("change", "#PatientId", function(event) {
        var val = this.value;
        getPatientVal(val);

    });

});
</script>
