 
<?php $__env->startSection('title', 'Client Registration Form'); ?>
<?php $__env->startSection('content'); ?>  
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.min.css">

<?php 
    $getstatecodedata = DB::table('state_master')->get();
    $getdistrictcodedata = DB::table('district_master')->get();

    $adminstatecode = auth()->user()->state_code;
    $admindistcode = auth()->user()->dist_code;
    $art_centre_code = auth()->user()->art_centre_code;
    $role_name  = auth()->user()->roles->pluck('name');
    if($role_name[0] == "Super Admin" || $role_name[0] == "Admin")
    {
        $getartcentredata = DB::table('art_centre_master')->get();
    }
    else
    {
        $art_centre_code = explode(', ',$art_centre_code);
        $getartcentredata = DB::table('art_centre_master')->whereIn('art_centre_code',$art_centre_code)->get();
    }
?>

<div class="container-fluid">
    <div class="page-header">
        <div class="row align-items-end">
            <div class="col-lg-8">
                <div class="page-header-title">
                    <i class="ik ik-edit bg-blue"></i>
                    <div class="d-inline">
                        <h5><?php echo e(__('Client Registration Form')); ?></h5>
                    </div>
                </div>
            </div>
            <div class="col-lg-4">
                <nav class="breadcrumb-container" aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item">
                            <a href="<?php echo e(route('dashboard')); ?>"><i class="ik ik-home"></i></a>
                        </li>
                        <li class="breadcrumb-item"><a href="#"><?php echo e(__('Forms')); ?></a></li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-7 mx-auto">
            <div class="card">
                <div class="card-header">
                    <div class="col-md-9 pl-0">
                        <h3><?php echo e(__('Client Registration Form')); ?></h3>
                    </div>
                    <div class="col-md-3 text-right">
                        <a href="<?php echo e('upload-patient'); ?>" class='btn btn-primary'><?php echo e(__('Import Client Register')); ?></a>
                    </div>
                </div>
                <div class="card-body">
                    <form class="forms-sample"  method='POST' <?php if(!empty($showdata)): ?> action="<?php echo e(url('updatepatient')); ?>" <?php else: ?> action="<?php echo e(url('insertpatient')); ?>" <?php endif; ?> name='patientregister'>
                        <?php echo csrf_field(); ?>
                        
                        <?php if(!empty($showdata)): ?>
                        <input type='hidden' name='id' value='<?php echo e($showdata[0]->id); ?>'>
                        <?php endif; ?>
                        
                        <input type="hidden" class="form-control" id="state_code" name='state_code' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->state_code); ?>' <?php } else{?> value='<?php echo e(auth()->user()->state_code); ?>'<?php } ?> placeholder="Enter State code" readonly>
                        <input type="hidden" class="form-control" id="dist_code" name='dist_code' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->dist_code); ?>' <?php } else{?> value='<?php echo e(auth()->user()->dist_code); ?>'<?php } ?> placeholder="Enter District code" readonly>
                        <input type="hidden" class="form-control" id="emp_code" name='emp_code' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->emp_code); ?>' <?php } else{?> value='<?php echo e(auth()->user()->emp_code); ?>'<?php } ?> placeholder="Enter Staff code" readonly>
                        <input type="hidden" class="form-control" id="art_centre_code" name='art_centre_code' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->art_centre_code); ?>' <?php } else{?> value='<?php echo e(auth()->user()->art_centre_code); ?>'<?php } ?> placeholder="Enter Staff code" readonly>
    
                        <div class="form-group">
                            <label for="doe"><?php echo e(__('1. Date of Entry')); ?></label>
                            <div class='input-group date datetimepicker'>
                                <input type='text' id='matregdate' <?php if(!empty($showdata)): ?> value='<?php echo e($showdata[0]->doe); ?>' <?php endif; ?> class="form-control" name="doe" placeholder="dd-mm-yyyy" required/>
                                <span class="input-group-addon">
                                  <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label for="state_code"><?php echo e(__('2. ART Center')); ?></label>
                            <select name='art_centre' id='art_centre' class='form-control' required>
                                <option value="">Select ART Center</option>
                                <?php foreach($getartcentredata as $getartcentre){ ?>
                                 <option value='<?php echo $getartcentre->art_centre_code; ?>' <?php if(!empty($showdata)): ?><?php echo e($showdata[0]->art_centre == $getartcentre->art_centre_code ? 'selected' : ''); ?> <?php endif; ?>><?php echo $getartcentre->art_centre_code.' | '.$getartcentre->name_of_artc; ?></option>
                                 <?php } ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="art_centre_name"><?php echo e(__('3. ART Center Name')); ?></label>
                            <input type="text" class="form-control" id="art_centre_name" name='art_centre_name' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->art_centre_name); ?>' <?php } ?> placeholder="Enter ART Center Name" readonly>
                        </div>
                        <div class="form-group">
                            <label for="pre_art_reg_num"><?php echo e(__('4. Pre ART REG Number')); ?></label>
                            <input type="text" class="form-control" id="pre_art_reg_num" name='pre_art_reg_num' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->pre_art_reg_num); ?>' <?php } ?> placeholder="Enter Pre ART REG Number" required>
                            <span style="color: red;display: none;" id="prereg_err"><b>Pre ART REG Number Should be Unique</b></span>
                        </div>
                        <div class="form-group">
                            <label for="art_reg_num"><?php echo e(__('5. ART REG Number')); ?></label>
                            <input type="text" class="form-control" id="art_reg_num" name='art_reg_num' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->art_reg_num); ?>' <?php } ?> placeholder="Enter ART REG Number" required>
                            <span style="color: red;display: none;" id="artreg_err"><b>Pre ART REG and ART REG Number can not be same.</b></span>
                            <span style="color: red;display: none;" id="reg_err"><b>ART REG Number Should be Unique</b></span>
                            
                        </div>
                        <div class="form-group">
                            <label for="pat_name"><?php echo e(__('6. Client Name')); ?></label>
                            <input type="text" class="form-control" id="pat_name" name='pat_name' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->pat_name); ?>' <?php } ?> placeholder="Enter Client Name" required>
                        </div>

                        <input type="hidden" name="today_date" id="today_date" value="<?php echo e(date('d-m-Y')); ?>">
                        <div class="form-group">
                            <label for="pat_dob"><?php echo e(__('7. Date of Birth')); ?></label>
                            <div class='input-group date datetimepicker'>
                                <input type='text' id='pat_dob' <?php if(!empty($showdata)): ?> value='<?php echo e($showdata[0]->pat_dob); ?>' <?php else: ?> <?php endif; ?> class="form-control" name="pat_dob" placeholder="dd-mm-yyyy"/>
                                <span class="input-group-addon">
                                  <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pat_age"><?php echo e(__('8. Client Age')); ?></label>
                            <input type="number" min="0" class="form-control" id="pat_age" name='pat_age' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->pat_age); ?>' <?php } ?> placeholder="Enter Client Age">
                        </div>
                        <div class="form-group">
                            <label for="pat_sex"><?php echo e(__('9. Client Sex')); ?></label><br>
                            <input type='radio' value="Male" name="pat_sex"  <?php if(!empty($showdata)): ?><?php echo e(($showdata[0]->pat_sex == 'Male')? "checked" : ""); ?> <?php endif; ?>><span class="pl-5 pr-10">Male</span>
                            <input type='radio' value="Female" name="pat_sex"  <?php if(!empty($showdata)): ?><?php echo e(($showdata[0]->pat_sex == 'Female')? "checked" : ""); ?> <?php endif; ?>><span class="pl-5 pr-10">Female</span>
                            <input type='radio' value="TG" name="pat_sex"  <?php if(!empty($showdata)): ?><?php echo e(($showdata[0]->pat_sex == 'TG')? "checked" : ""); ?> <?php endif; ?>><span class="pl-5">TG</span>
                        </div>
                        <div class="form-group">
                            <label for="pat_mobile"><?php echo e(__('10. Client Mobile')); ?></label>
                            <input type="text" maxlength="10" minlength="10" onkeypress=" return isNumber(event)" class="form-control" id="pat_mobile" name='pat_mobile' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->pat_mobile); ?>' <?php } ?> placeholder="Enter Client Mobile">
                            <span style="color: red;display: none;" id="patmobile_err"><b>Mobile Number Already Exists</b></span>
                            <span style="color: red;display: none;" id="patmobile_req_err"><b>Primary Mobile Number Should be required.</b></span>
                        </div>
                        <div class="form-group">
                            <label for="pat_alternate_mobile"><?php echo e(__('11. Client Alternate Mobile')); ?></label>
                            <input type="text" maxlength="10" minlength="10" onkeypress=" return isNumber(event)" class="form-control" id="pat_alternate_mobile" name='pat_alternate_mobile' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->pat_alternate_mobile); ?>' <?php } ?> placeholder="Enter Client Alternate Mobile">
                        </div>
                        <div class="form-group">
                            <label for="pat_district"><?php echo e(__('12. Client District')); ?></label>
                            <select name='pat_district'  class='form-control' value='Select Option' id="pat_district">
                                <option value="">Select District Code</option>
                                <?php foreach($getdistrictcodedata as $getdistrictcode){ ?>
                                 <option value='<?php echo $getdistrictcode->district_code; ?>' <?php if(!empty($showdata)): ?><?php echo e($showdata[0]->pat_district == $getdistrictcode->district_code ? 'selected' : ''); ?> <?php endif; ?> ><?php echo $getdistrictcode->district_code.' | '.$getdistrictcode->district_name; ?></option>
                                 <?php } ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="pat_city"><?php echo e(__('13. Client City')); ?></label>
                            <input type="text" class="form-control" id="pat_city" name='pat_city' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->pat_city); ?>' <?php } ?> placeholder="Enter Client City">
                        </div>
                        <div class="form-group">
                            <label for="pat_mandal"><?php echo e(__('14. Client Subdistrict- Mandal/Block')); ?></label>
                            <input type="text" class="form-control" id="pat_mandal" name='pat_mandal' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->pat_mandal); ?>' <?php } ?> placeholder="Enter Client Subdistrict- Mandal/Block">
                        </div>
                        <div class="form-group">
                            <label for="pat_address"><?php echo e(__('15. Client Address')); ?></label>
                            <input type="text" class="form-control" id="pat_address" name='pat_address' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->pat_address); ?>' <?php } ?> placeholder="Enter Client Address">
                        </div>
                        <div class="form-group">
                            <label for="pat_pincode"><?php echo e(__('16. Client Pincode')); ?></label>
                            <input type="text" maxlength="6" onkeypress=" return isNumber(event)" class="form-control" id="pat_pincode" name='pat_pincode' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->pat_pincode); ?>' <?php } ?> placeholder="Enter Client Pincode">
                        </div>
                        <div class="form-group">
                            <label for="pat_status"><?php echo e(__('17. Client Status')); ?></label><br>
                            <input type='radio' value="Currently on Follow-up" name="pat_status"  <?php if(!empty($showdata)): ?><?php echo e(($showdata[0]->pat_status == 'Currently on Follow-up')? "checked" : ""); ?> <?php endif; ?>><span class="pl-5 pr-10">Currently on Follow-up</span>
                            <input type='radio' value="Dead" name="pat_status"  <?php if(!empty($showdata)): ?><?php echo e(($showdata[0]->pat_status == 'Dead')? "checked" : ""); ?> <?php endif; ?>><span class="pl-5 pr-10">Dead</span>
                        </div>
                        <br><br>
                        <button type="submit" id="submit" class="btn btn-primary mr-2"><?php echo e(__('Submit')); ?></button>
                        <?php if(empty($showdata)): ?>
                        <a href="<?php echo e('patient-register-data'); ?>" class="btn btn-light"><?php echo e(__('Cancel')); ?></a>
                        <?php endif; ?>
                      </form>
                </div>
            </div>
        </div>
    </div>
</div>
    
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<script>  
    $(function() {  
        var default_date=  new Date();
        $('.datetimepicker').datetimepicker({  
           format: 'DD-MM-YYYY', 
            useCurrent:false, 
            defaultDate: default_date
        });
        $("select").select2();
    });  

    function isNumber(evt)
    {
        evt = (evt) ? evt : window.event;
        var charCode = (evt.which) ? evt.which : evt.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
        return true; 
    }

    $("#pat_dob").blur(function() { 
        var selectedDate = $('#pat_dob').val();
        var todayDate = $('#today_date').val();

        var from = selectedDate.split("-");
        var from2 = todayDate.split("-");
        var date2 = new Date(from[2], from[1], from[0]);
        var date1 = new Date(from2[2], from2[1], from2[0]);
        var dy = date1.getYear()  - date2.getYear();
        
        var dm = date1.getMonth() - date2.getMonth();
        dd = date1.getDate()  - date2.getDate();

        if (dd < 0) { dm -= 1; dd += 30; }
        if (dm < 0) { dy -= 1; dm += 12; }
        $('#pat_age').val(dy);
        $('#pat_age').attr('readonly',true);
    });

    $("#pat_age").blur(function() { 
        $('#pat_dob').attr('readonly',true);
    });

    $("#pat_mobile").blur(function() { 
        var pat_mobile = $('#pat_mobile').val();
        if(pat_mobile == "")
        {
            $('#patmobile_req_err').css('display','block');
        }  
        else
        {
            $('#patmobile_req_err').css('display','none');
        }     
    });

    $("#pat_alternate_mobile").blur(function() { 
        var pat_alternate_mobile = $('#pat_alternate_mobile').val();
        var pat_mobile = $('#pat_mobile').val();
        if(pat_mobile != "")
        {
            if(pat_mobile == pat_alternate_mobile)
            {
                $('#pat_alternate_mobile').val('');
                alert('Primary number & alternate number should not be same.');
            }
        }       
    });
    
    $( "#art_centre" ).change(function() { 
        var art_centre = $(this).val();
        $.ajax({
            type: "POST",
            url: "<?php echo e(url('getartcentrename')); ?>",
            data: {art_centre:art_centre, _token: '<?php echo e(csrf_token()); ?>' },
            dataType: "json",
            success: function(res) { 
                var art_centre_name = res.showdata.name_of_artc;
                $('#art_centre_name').val(art_centre_name);
            },
            error: function (jqXHR, exception) {

            }
        });
    });

    $( "#pat_mobile" ).blur(function() { 
        var pat_mobile = $(this).val();
        $.ajax({
            type: "POST",
            url: "<?php echo e(url('checkpatmobile')); ?>",
            data: {pat_mobile:pat_mobile, _token: '<?php echo e(csrf_token()); ?>' },
            dataType: "json",
            success: function(res) { 
                var mobilecount = res.showdata;
                if(mobilecount > 0)
                {
                    $('#patmobile_err').css('display','block');
                }
                else
                {
                    $('#patmobile_err').css('display','none');
                }
            },
            error: function (jqXHR, exception) {

            }
        });
    });

    $( "#pre_art_reg_num" ).blur(function() { 
        var pre_art_reg_num = $(this).val();
        var art_reg_num = $('#art_reg_num').val();
        var art_centre_code = $('#art_centre_code').val();
        console.log(art_centre_code);
        $.ajax({
            type: "POST",
            url: "<?php echo e(url('checkartreg')); ?>",
            data: {pre_art_reg_num:pre_art_reg_num, art_reg_num:art_reg_num, art_centre_code:art_centre_code, _token: '<?php echo e(csrf_token()); ?>' },
            dataType: "json",
            success: function(res) { 
                console.log(res);
                var preregcount = res.preregcount;
                var showdata = res.showdata;
                console.log(showdata);
                if(preregcount > 0)
                {
                    $('#prereg_err').css('display','block');
                    $('#submit').prop('disabled', true);
                }
                else
                {
                    $('#prereg_err').css('display','none');
                    $('#submit').prop('disabled', false);
                }

                if(showdata > 0)
                {
                    $('#submit').prop('disabled', true);
                }
                else
                {
                    $('#submit').prop('disabled', false);
                }

                if(pre_art_reg_num == art_reg_num)
                {
                    $('#artreg_err').css('display','block');
                    $('#submit').prop('disabled', true);
                }
                else
                {
                    $('#artreg_err').css('display','none');
                    $('#submit').prop('disabled', false);
                }
            },
            error: function (jqXHR, exception) {

            }
        });
    });

    $( "#art_reg_num" ).blur(function() { 
        var art_reg_num = $(this).val();
        var pre_art_reg_num = $('#pre_art_reg_num').val();

        $.ajax({
            type: "POST",
            url: "<?php echo e(url('checkartreg')); ?>",
            data: {pre_art_reg_num:pre_art_reg_num, art_reg_num:art_reg_num, _token: '<?php echo e(csrf_token()); ?>' },
            dataType: "json",
            success: function(res) { 
                var regcount = res.regcount;
                var showdata = res.showdata;
                console.log(showdata);
                if(regcount > 0)
                {
                    $('#reg_err').css('display','block');
                    $('#submit').prop('disabled', true);
                }
                else
                {
                    $('#reg_err').css('display','none');
                    $('#submit').prop('disabled', false);
                }

                if(showdata > 0)
                {
                    $('#submit').prop('disabled', true);
                }
                else
                {
                    $('#submit').prop('disabled', false);
                }

                if(pre_art_reg_num == art_reg_num)
                {
                    $('#artreg_err').css('display','block');
                    $('#submit').prop('disabled', true);
                }
                else
                {
                    $('#artreg_err').css('display','none');
                    $('#submit').prop('disabled', false);
                }
            },
            error: function (jqXHR, exception) {

            }
        });
    });    
</script>
<?php $__env->startPush('script'); ?>
    <script src="<?php echo e(asset('js/form-components.js')); ?>"></script>
<?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/yrgdmc/public_html/treatment/resources/views/pages/patient-register.blade.php ENDPATH**/ ?>