@extends('layouts.yellow')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header bg-primary">
                    <h3 class="card-title text-white">
                        <i class="fas fa-cogs mr-2"></i>
                        {{ __('common-table.configure-history.title') }}
                    </h3>
                </div>
                <div class="card-body">
                    <div class="alert alert-info">
                        <i class="fas fa-info-circle mr-2"></i>
                        {{ __('common-table.configure-history.info') }}
                    </div>

                    <form action="{{ route('/admin/configure-history-save') }}" method="POST" id="configureHistoryForm">
                        @csrf
                        <input type="hidden" name="especiality_id" id="especiality_id" value="{{ request('especiality_id') }}">
                        

                        
                        <!-- Antecedentes -->
                        <div class="card mb-4">
                            <div class="card-header bg-primary">
                                <h4 class="mb-0 text-white">
                                    <i class="fas fa-history mr-2"></i>
                                    {{ __('common-table.configure-history.antecedents') }}
                                </h4>
                            </div>
                            <div class="card-body">
                                <p class="text-muted mb-3">{{ __('common-table.configure-history.selectAntecedents') }}</p>
                                <div class="row">
                                    @foreach($sectionTypes as $sectionType)
                                        @if($sectionType->section_type_id !== null)
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" 
                                                       id="sectionType{{ $sectionType->id }}" 
                                                       name="section_types[]" 
                                                       value="{{ $sectionType->id }}"
                                                       {{ (isset($configuration) && $configuration && in_array($sectionType->id, $configuration->section_types ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="sectionType{{ $sectionType->id }}">
                                                    {{ __("backgrounds.".$sectionType->value) }}
                                                </label>
                                            </div>
                                        </div>
                                        @endif
                                    @endforeach
                                </div>
                            </div>
                        </div>

                        <!-- Exámenes Médicos -->
                        <div class="card">
                            <div class="card-header bg-primary">
                                <h4 class="mb-0 text-white">
                                    <i class="fas fa-stethoscope mr-2"></i>
                                    {{ __('common-table.configure-history.medicalExams') }}
                                </h4>
                            </div>
                            <div class="card-body">
                                <!-- Signos Vitales -->
                                <div class="mb-4">
                                    <h5 class="border-bottom pb-2 text-primary">
                                        <i class="fas fa-heartbeat mr-2"></i>
                                        {{ __('common-table.configure-history.vitalSigns') }}
                                    </h5>
                                    <div class="row">
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examP1" name="medical_exams[]" value="p1" 
                                                    {{ (isset($configuration) && $configuration && in_array('p1', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examWeight">
                                                    <i class="fas fa-weight text-primary mr-1"></i>
                                                    {{ __("com-form-history.p1") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examP2" name="medical_exams[]" value="p2" 
                                                    {{ (isset($configuration) && $configuration && in_array('p2', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examWeight">
                                                    <i class="fas fa-weight text-primary mr-1"></i>
                                                    {{ __("com-form-history.p2") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examP3" name="medical_exams[]" value="p3" 
                                                       {{ (isset($configuration) && $configuration && in_array('p3', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examWeight">
                                                    <i class="fas fa-weight text-primary mr-1"></i>
                                                    {{ __("com-form-history.p3") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examSize" name="medical_exams[]" value="Size" 
                                                       {{ (isset($configuration) && $configuration && in_array('Size', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examSize">
                                                    <i class="fas fa-ruler-vertical text-primary mr-1"></i>
                                                    {{ __("com-form-history.Size") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examTA" name="medical_exams[]" value="TA" 
                                                       {{ (isset($configuration) && $configuration && in_array('TA', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examTA">
                                                    <i class="fas fa-tachometer-alt text-primary mr-1"></i>
                                                    {{ __("com-form-history.TA") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examTemp" name="medical_exams[]" value="Temp" 
                                                       {{ (isset($configuration) && $configuration && in_array('Temp', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examTemp">
                                                    <i class="fas fa-thermometer-half text-primary mr-1"></i>
                                                    {{ __("com-form-history.Temp") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examC_FC" name="medical_exams[]" value="C_FC" 
                                                       {{ (isset($configuration) && $configuration && in_array('C_FC', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examC_FC">
                                                    <i class="fas fa-heart text-primary mr-1"></i>
                                                    {{ __("com-form-history.C_FC") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examFR" name="medical_exams[]" value="FR" 
                                                       {{ (isset($configuration) && $configuration && in_array('FR', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examFR">
                                                    <i class="fas fa-lungs text-primary mr-1"></i>
                                                    {{ __("com-form-history.FR") }}
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <!-- Examen Físico -->
                                <div class="mb-4">
                                    <h5 class="border-bottom pb-2 text-primary">
                                        <i class="fas fa-user-md mr-2"></i>
                                        {{ __('common-table.configure-history.physicalExam') }}
                                    </h5>
                                    <div class="row">
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examGeneral" name="medical_exams[]" value="General" 
                                                       {{ (isset($configuration) && $configuration && in_array('General', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examGeneral">
                                                    <i class="fas fa-user text-primary mr-1"></i>
                                                    {{ __("com-form-history.General") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examSkin" name="medical_exams[]" value="Skin" 
                                                       {{ (isset($configuration) && $configuration && in_array('Skin', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examSkin">
                                                    <i class="fas fa-hand-paper text-primary mr-1"></i>
                                                    {{ __("com-form-history.Skin") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examHead" name="medical_exams[]" value="Head" 
                                                       {{ (isset($configuration) && $configuration && in_array('Head', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examHead">
                                                    <i class="fas fa-head-side-mask text-primary mr-1"></i>
                                                    {{ __("com-form-history.Head") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examEyes" name="medical_exams[]" value="Eyes" 
                                                       {{ (isset($configuration) && $configuration && in_array('Eyes', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examEyes">
                                                    <i class="fas fa-eye text-primary mr-1"></i>
                                                    {{ __("com-form-history.Eyes") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examORL" name="medical_exams[]" value="ORL" 
                                                       {{ (isset($configuration) && $configuration && in_array('ORL', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examORL">
                                                    <i class="fas fa-ear text-primary mr-1"></i>
                                                    {{ __("com-form-history.ORL") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examNeck" name="medical_exams[]" value="Neck" 
                                                       {{ (isset($configuration) && $configuration && in_array('Neck', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examNeck">
                                                    <i class="fas fa-neck text-primary mr-1"></i>
                                                    {{ __("com-form-history.Neck") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examCardioPulmonary" name="medical_exams[]" value="Cardio_Pulmonary" 
                                                       {{ (isset($configuration) && $configuration && in_array('Cardio_Pulmonary', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examCardioPulmonary">
                                                    <i class="fas fa-heartbeat text-primary mr-1"></i>
                                                    {{ __("com-form-history.Cardio_Pulmonary") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examAbdomen" name="medical_exams[]" value="Abdomen" 
                                                       {{ (isset($configuration) && $configuration && in_array('Abdomen', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examAbdomen">
                                                    <i class="fas fa-stomach text-primary mr-1"></i>
                                                    {{ __("com-form-history.Abdomen") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examGenitourinary" name="medical_exams[]" value="Genitourinary_and_rectal" 
                                                       {{ (isset($configuration) && $configuration && in_array('Genitourinary_and_rectal', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examGenitourinary">
                                                    <i class="fas fa-procedures text-primary mr-1"></i>
                                                    {{ __("com-form-history.Genitourinary_and_rectal") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examExtremities" name="medical_exams[]" value="Extremities" 
                                                       {{ (isset($configuration) && $configuration && in_array('Extremities', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examExtremities">
                                                    <i class="fas fa-hand-holding-medical text-primary mr-1"></i>
                                                    {{ __("com-form-history.Extremities") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examNeurologist" name="medical_exams[]" value="Neurologist" 
                                                       {{ (isset($configuration) && $configuration && in_array('Neurologist', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examNeurologist">
                                                    <i class="fas fa-brain text-primary mr-1"></i>
                                                    {{ __("com-form-history.Neurologist") }}
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <!-- Estudios y Comentarios -->
                                <div class="mb-4">
                                    <h5 class="border-bottom pb-2 text-primary">
                                        <i class="fas fa-file-medical-alt mr-2"></i>
                                        {{ __('common-table.configure-history.studiesAndComments') }}
                                    </h5>
                                    <div class="row">
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examParaclinical" name="medical_exams[]" value="Paraclinical_Studies" 
                                                       {{ (isset($configuration) && $configuration && in_array('Paraclinical_Studies', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examParaclinical">
                                                    <i class="fas fa-microscope text-primary mr-1"></i>
                                                    {{ __("com-form-history.Paraclinical_Studies") }}
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="examComment" name="medical_exams[]" value="Comment" 
                                                       {{ (isset($configuration) && $configuration && in_array('Comment', $configuration->medical_exams ?? [])) ? 'checked' : '' }}>
                                                <label class="custom-control-label" for="examComment">
                                                    <i class="fas fa-comment-medical text-primary mr-1"></i>
                                                    {{ __("com-form-history.Comment") }}
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="text-center mt-4">
                            <button type="submit" class="btn btn-primary btn-lg">
                                <i class="fas fa-save mr-2"></i>
                                {{ __('common-table.configure-history.save') }}
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Modal de Error Mejorado con Card -->
<div class="modal fade" id="errorModal" tabindex="-1" role="dialog" aria-labelledby="errorModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content border-0 shadow">
            <div class="card">
                <div class="card-header bg-gradient-primary text-white">
                </div>
                <div class="card-body py-4">
                    <div class="text-center mb-3">
                        <i class="fas fa-exclamation-triangle text-warning fa-3x"></i>
                    </div>
                    <p id="errorModalText" class="text-center mb-0"></p>
                </div>
                <div class="card-footer bg-light border-0">
                    <div class="text-center">
                        <button type="button" class="btn btn-primary" data-dismiss="modal">
                            <i class="fas fa-check mr-2"></i>{{ __('common-table.configure-history.understood') }}
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@include('components.utils-form')

<script>
    $(document).ready(function() {
        // Función para mostrar mensajes de error en un modal
        function showError(message) {
            $("#errorModalText").text(message);
            $("#errorModal").modal('show');
        }
        
        // Asegurarse de que el modal se cierre correctamente
        $(".modal .close, .modal .btn").on("click", function() {
            $("#errorModal").modal('hide');
        });
        
        // Verificar si hay errores de validación y mostrarlos
        @if(session('error'))
            showError("{{ session('error') }}");
        @endif
        
        // Definir validaciones para el formulario
        $.fn.validations = function() {
            return [
                {
                    "name": "noEmpty",
                    "message": "Este campo es requerido",
                    "run": function(field) {
                        // Verificar que al menos un tipo de sección esté seleccionado
                        if (field.key === "section_types[]") {
                            return $("input[name='section_types[]']:checked").length > 0;
                        }
                        // Verificar que al menos un examen médico esté seleccionado
                        if (field.key === "medical_exams[]") {
                            return $("input[name='medical_exams[]']:checked").length > 0;
                        }
                        return true;
                    }
                }
            ];
        };

        // Validar el formulario antes de enviarlo
        $("#configureHistoryForm").on("submit", function(e) {
            let form = document.querySelector("#configureHistoryForm");
            let data = $.fn.getDataForm.call(this, form);
            
            // Validar especialidad
            if (!$("#especiality_id").val()) {
                e.preventDefault();
                showError("{{ __('common-table.configure-history.selectEspecialityRequired') }}");
                return false;
            }
            
            // Validar que al menos un tipo de sección esté seleccionado
            if ($("input[name='section_types[]']:checked").length === 0) {
                e.preventDefault();
                showError("{{ __('common-table.configure-history.selectAtLeastOneAntecedent') }}");
                return false;
            }
            
            // Validar que al menos un signo vital esté seleccionado
            let signosVitales = ["Weight", "Size", "TA", "Temp", "C_FC", "FR"];
            let signosVitalesSeleccionados = false;
            signosVitales.forEach(function(valor) {
                if ($("input[name='medical_exams[]'][value='" + valor + "']:checked").length > 0) {
                    signosVitalesSeleccionados = true;
                }
            });
            
            if (!signosVitalesSeleccionados) {
                e.preventDefault();
                showError("{{ __('common-table.configure-history.selectAtLeastOneVitalSign') }}");
                return false;
            }
            
            // Validar que al menos un examen físico esté seleccionado
            let examenesFisicos = ["General", "Skin", "Head", "Eyes", "ORL", "Neck", "Cardio_Pulmonary", 
                                  "Abdomen", "Genitourinary_and_rectal", "Extremities", "Neurologist"];
            let examenesFisicosSeleccionados = false;
            examenesFisicos.forEach(function(valor) {
                if ($("input[name='medical_exams[]'][value='" + valor + "']:checked").length > 0) {
                    examenesFisicosSeleccionados = true;
                }
            });
            
            if (!examenesFisicosSeleccionados) {
                e.preventDefault();
                showError("{{ __('common-table.configure-history.selectAtLeastOnePhysicalExam') }}");
                return false;
            }
            
            // Validar que al menos un estudio o comentario esté seleccionado
            let estudiosComentarios = ["Paraclinical_Studies", "Comment"];
            let estudiosComentariosSeleccionados = false;
            estudiosComentarios.forEach(function(valor) {
                if ($("input[name='medical_exams[]'][value='" + valor + "']:checked").length > 0) {
                    estudiosComentariosSeleccionados = true;
                }
            });
            
            if (!estudiosComentariosSeleccionados) {
                e.preventDefault();
                showError("{{ __('common-table.configure-history.selectAtLeastOneStudyOrComment') }}");
                return false;
            }
            
            // Asegurarse de que los arrays de checkboxes estén incluidos en los datos
            data["section_types[]"] = $("input[name='section_types[]']:checked").length > 0 ? "selected" : "";
            data["medical_exams[]"] = $("input[name='medical_exams[]']:checked").length > 0 ? "selected" : "";
            
            let valid = $.fn.runValidations(data, $.fn.validations());
            if (!valid.valid) {
                e.preventDefault();
            }
        });
        
        // Agregar botones para seleccionar/deseleccionar todos
        // Para antecedentes
        $(".card-header:contains('Antecedentes')").append(
            '<div class="float-right">' +
            '<button type="button" class="btn btn-sm btn-outline-light mr-2 select-all-antecedents">' +
            '<i class="fas fa-check-square mr-1"></i>Seleccionar todos</button>' +
            '<button type="button" class="btn btn-sm btn-outline-light deselect-all-antecedents">' +
            '<i class="fas fa-square mr-1"></i>Deseleccionar todos</button>' +
            '</div>'
        );
        
        // Para exámenes médicos de signos vitales
        $("h5:contains('Signos Vitales')").append(
            '<div class="float-right">' +
            '<button type="button" class="btn btn-sm btn-outline-primary mr-2 select-all-vital-signs">' +
            '<i class="fas fa-check-square mr-1"></i>Todos</button>' +
            '<button type="button" class="btn btn-sm btn-outline-primary deselect-all-vital-signs">' +
            '<i class="fas fa-square mr-1"></i>Ninguno</button>' +
            '</div>'
        );
        
        // Para exámenes físicos
        $("h5:contains('Examen Físico')").append(
            '<div class="float-right">' +
            '<button type="button" class="btn btn-sm btn-outline-primary mr-2 select-all-physical-exam">' +
            '<i class="fas fa-check-square mr-1"></i>Todos</button>' +
            '<button type="button" class="btn btn-sm btn-outline-primary deselect-all-physical-exam">' +
            '<i class="fas fa-square mr-1"></i>Ninguno</button>' +
            '</div>'
        );
        
        // Para estudios y comentarios
        $("h5:contains('Estudios y Comentarios')").append(
            '<div class="float-right">' +
            '<button type="button" class="btn btn-sm btn-outline-primary mr-2 select-all-studies">' +
            '<i class="fas fa-check-square mr-1"></i>Todos</button>' +
            '<button type="button" class="btn btn-sm btn-outline-primary deselect-all-studies">' +
            '<i class="fas fa-square mr-1"></i>Ninguno</button>' +
            '</div>'
        );
        
        // Eventos para los botones de seleccionar/deseleccionar todos
        $(".select-all-antecedents").on("click", function() {
            $("input[name='section_types[]']").prop('checked', true);
        });
        
        $(".deselect-all-antecedents").on("click", function() {
            $("input[name='section_types[]']").prop('checked', false);
        });
        
        $(".select-all-vital-signs").on("click", function() {
            ["Weight", "Size", "TA", "Temp", "C_FC", "FR"].forEach(function(valor) {
                $("input[name='medical_exams[]'][value='" + valor + "']").prop('checked', true);
            });
        });
        
        $(".deselect-all-vital-signs").on("click", function() {
            ["Weight", "Size", "TA", "Temp", "C_FC", "FR"].forEach(function(valor) {
                $("input[name='medical_exams[]'][value='" + valor + "']").prop('checked', false);
            });
        });
        
        $(".select-all-physical-exam").on("click", function() {
            ["General", "Skin", "Head", "Eyes", "ORL", "Neck", "Cardio_Pulmonary", 
             "Abdomen", "Genitourinary_and_rectal", "Extremities", "Neurologist"].forEach(function(valor) {
                $("input[name='medical_exams[]'][value='" + valor + "']").prop('checked', true);
            });
        });
        
        $(".deselect-all-physical-exam").on("click", function() {
            ["General", "Skin", "Head", "Eyes", "ORL", "Neck", "Cardio_Pulmonary", 
             "Abdomen", "Genitourinary_and_rectal", "Extremities", "Neurologist"].forEach(function(valor) {
                $("input[name='medical_exams[]'][value='" + valor + "']").prop('checked', false);
            });
        });
        
        $(".select-all-studies").on("click", function() {
            ["Paraclinical_Studies", "Comment"].forEach(function(valor) {
                $("input[name='medical_exams[]'][value='" + valor + "']").prop('checked', true);
            });
        });
        
        $(".deselect-all-studies").on("click", function() {
            ["Paraclinical_Studies", "Comment"].forEach(function(valor) {
                $("input[name='medical_exams[]'][value='" + valor + "']").prop('checked', false);
            });
        });
    });
</script>
@endsection 