
<div class="panel"> 
    <div class="panel-body">
        <form role="form" class="form-horizontal" action="<?= base_url('update_delivery_status'); ?>" method="POST">
            <h2 class="text-center">Pregnant Women Update Status</h2>  
            <hr class="colorgraph">

            <div class="panel">
                <div class="panel-body">
                    <div class="row">
                        <div class="col-md-3 col-md-push-2"><p class="text-center text-success" id="women_name">Women Name:</p></div>
                        <div class="col-md-3 col-md-push-3"><p class="text-center text-success" id="lpm_date">LPM Date:</p></div>
                        <div class="col-md-3 col-md-push-3"><p class="text-center text-success" id="current_week">Running Week:<p></div>
                    </div>
                    <div class="row">
                        <div class="col-md-6 col-md-push-3">
                            <div class="form-group">
                                <div class="input-group">
                                    <span class="input-group-addon"><i aria-hidden="true"></i>Select Pregnant Women</span>
                                    <select id="pregnant_id" name="pregnant_id" required class="form-control">
                                        <option value="0" disabled="true" selected> Select Women</option>
                                        <?php
                                        if (isset($pregnant_list) and $pregnant_list) {
                                            for ($i = 0; $i < count($pregnant_list); $i++) {
                                                ?>
                                                <option value=<?= $pregnant_list[$i]['pregnant_id'] ?>> <?= $pregnant_list[$i]['name'] ?></option>
                                                <?php
                                            }
                                        }
                                        ?>

                                    </select>
                                    <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                                </div>                    
                            </div> 
                        </div>
                        <div class="col-md-1 col-md-push-3 spinner" id="pregnant_spinner" style="display: none;margin-top: 5px">
                            <i class="fa fa-spinner fa-spin"></i>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6 col-md-push-3">
                            <div class="form-group">
                                <div class="input-group">
                                    <span class="input-group-addon"><i aria-hidden="true"></i>Select Current Status</span>
                                    <select id="pregnancy_status" name="pregnancy_status" required class="form-control">
                                        <option value="0" disabled="true" selected> Select Status</option>
                                        <option value="1">Delivered </option>
                                        <option value="2">Aborted </option>
                                        <option value="3">Died </option>
                                        <option value="4">Migrated </option>
                                        <option value="5">Other</option>
                                    </select>
                                    <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                                </div>                    
                            </div> 
                        </div>
                    </div>
                    <div class="row" id="div_delivery_location" style="display: none">
                        <div class="col-md-6 col-md-push-3">
                            <div class="form-group">
                                <div class="input-group">
                                    <span class="input-group-addon"><i aria-hidden="true"></i>Delivery Location</span>
                                    <select id="delivery_location" name="delivery_location"class="form-control">
                                        <option value="0" disabled="true" selected> Select Location</option>
                                        <option value="1">At Hospital</option>
                                        <option value="2">At Home</option>
                                    </select>
                                    <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                                </div>                    
                            </div> 
                        </div>
                    </div>
           



                    <div class="row" id="div_baby_current_status" style="display: none">
                        <div class="col-md-6 col-md-push-3">
                            <div class="form-group">
                                <div class="input-group">
                                    <span class="input-group-addon"><i aria-hidden="true"></i>Baby Current Status</span>
                                    <select id="baby_current_status" name="baby_current_status" class="form-control">
                                        <option value="0" disabled="true" selected> Select Status</option>
                                        <option value="live">Live Born</option>
                                        <option value="mixed">Mixed Born </option>
                                        <option value="still">Stillborn </option>
                                        
                                    </select>
                                    <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                                </div>                    
                            </div> 
                        </div>
                    </div>

                </div>
                <hr class="colorgraph">
                <div class="row">
                    <div class="col-xs-8 col-md-4 col-md-offset-4 col-xs-offset-2"><input type="submit" value="Update Pregnant Status" class="btn btn-primary btn-block"></div>            
                </div>
        </form>
    </div>
</div>
</div>





<script type="text/javascript">
    $(document).ready(function () {
        
        $('#pregnancy_status').change(function (){
           
            switch(parseInt($(this).val())){
                case 1:
                    $('#div_delivery_location').css('display','block');
                    $('#div_baby_current_status').css('display','block');
                    
                    
                    break;
                case 2:
                    $('#div_delivery_location').css('display','none');
                    $('#div_baby_current_status').css('display','none');
                    
                    break;
                case 3:
                    $('#div_delivery_location').css('display','block');
                    $('#div_baby_current_status').css('display','block');
                    
                    break;
                case 4:
                    $('#div_delivery_location').css('display','none');
                    $('#div_baby_current_status').css('display','none');
                    
                    break;
            }
        });
        
        
        $('#pregnant_id').change(function () {
            $('#pregnant_spinner').css('display', 'block');



            $.ajax({
                url: '<?= base_url('get_current_week') ?>',
                data: {
                    pregnant_id: $(this).val()
                },
                type: "POST",
                success: function (json) {
                    var data = $.parseJSON(json);
                    if (data['status']) {
                        $('#week_id').val(parseInt(data['current_week']));
                        $("#women_name").text("Women Name: " + $("#pregnant_id option:selected").text());
                        $("#lpm_date").text("LPM Date: " + data['lpm_date']);
                        $("#current_week").text("Running Week: " + data['current_week']);
                    }
                },
                error: function (xhr, status, errorThrown) {

                    $('#pregnant_spinner').css('display', 'none');
                },
                complete: function (xhr, status) {
                    $('#pregnant_spinner').css('display', 'none');
                }
            });
        });




        $('#radioBtnY0').on('click', function () {
            $('#question_ans0').val(parseInt(2));
            $('#radioBtnN0').removeClass('active').addClass('notActive');
            $('#radioBtnY0').removeClass('notActive').addClass('active');
        });
        $('#radioBtnN0').on('click', function () {
            $('#question_ans0').val(parseInt(1));
            $('#radioBtnY0').removeClass('active').addClass('notActive');
            $('#radioBtnN0').removeClass('notActive').addClass('active');

        });




        $('#radioBtnY1').on('click', function () {
            $('#question_ans1').val(parseInt(2));
            $('#radioBtnN1').removeClass('active').addClass('notActive');
            $('#radioBtnY1').removeClass('notActive').addClass('active');
        });
        $('#radioBtnN1').on('click', function () {
            $('#question_ans1').val(parseInt(1));
            $('#radioBtnY1').removeClass('active').addClass('notActive');
            $('#radioBtnN1').removeClass('notActive').addClass('active');

        });





        $('#radioBtnY2').on('click', function () {
            $('#question_ans2').val(parseInt(2));
            $('#radioBtnN2').removeClass('active').addClass('notActive');
            $('#radioBtnY2').removeClass('notActive').addClass('active');
        });
        $('#radioBtnN2').on('click', function () {
            $('#question_ans2').val(parseInt(1));
            $('#radioBtnY2').removeClass('active').addClass('notActive');
            $('#radioBtnN2').removeClass('notActive').addClass('active');

        });



        $('#radioBtnY3').on('click', function () {
            $('#question_ans3').val(parseInt(2));
            $('#radioBtnN3').removeClass('active').addClass('notActive');
            $('#radioBtnY3').removeClass('notActive').addClass('active');
        });
        $('#radioBtnN3').on('click', function () {
            $('#question_ans3').val(parseInt(1));
            $('#radioBtnY3').removeClass('active').addClass('notActive');
            $('#radioBtnN3').removeClass('notActive').addClass('active');

        });



        $('#radioBtnY4').on('click', function () {
            $('#question_ans4').val(parseInt(2));
            $('#radioBtnN4').removeClass('active').addClass('notActive');
            $('#radioBtnY4').removeClass('notActive').addClass('active');
        });
        $('#radioBtnN4').on('click', function () {
            $('#question_ans4').val(parseInt(1));
            $('#radioBtnY4').removeClass('active').addClass('notActive');
            $('#radioBtnN4').removeClass('notActive').addClass('active');

        });


    });
</script>
