diff --git a/resources/views/form/rapport-team3/1795590118-9f6c5d7f-2410-4bae-89bc-ab3d9ea2a684.blade.php b/resources/views/form/rapport-team3/1795590118-9f6c5d7f-2410-4bae-89bc-ab3d9ea2a684.blade.php index 65e63d75..2cd7abff 100644 --- a/resources/views/form/rapport-team3/1795590118-9f6c5d7f-2410-4bae-89bc-ab3d9ea2a684.blade.php +++ b/resources/views/form/rapport-team3/1795590118-9f6c5d7f-2410-4bae-89bc-ab3d9ea2a684.blade.php @@ -351,6 +351,68 @@ $('#report-form').append(''); } + + +// MSL Code and Speciality update function +function updateDoctorDetails() { + + let visitType = $('#field-visit_type').val(); + + let selectedOption; + + if (visitType === 'Doctor') { + selectedOption = $('#field-contact_id option:selected'); + } + else if (visitType === 'Chemist') { + selectedOption = $('#field-chemist_name option:selected'); + } + + if (selectedOption && selectedOption.val()) { + $('#field-msl_code').val(selectedOption.attr('msl_code') || ''); + $('#field-speciality').val(selectedOption.attr('speciality') || ''); + } +} + +// Doctor dropdown change +$('#field-contact_id').on('change', function () { + updateDoctorDetails(); +}); + +// Chemist dropdown change +$('#field-chemist_name').on('change', function () { + updateDoctorDetails(); +}); + +// Visit type change +$('#field-visit_type').on('change', function () { + + let type = $(this).val(); + + if (type === 'Doctor') { + $('#field-contact_id').parent().show(); + $('#field-contact_id').attr('required', true); + + $('#field-chemist_name').parent().hide(); + $('#field-chemist_name').attr('required', false); + } + else if (type === 'Chemist') { + $('#field-chemist_name').parent().show(); + $('#field-chemist_name').attr('required', true); + + $('#field-contact_id').parent().hide(); + $('#field-contact_id').attr('required', false); + } + else { + $('#field-contact_id, #field-chemist_name').parent().hide(); + $('#field-contact_id, #field-chemist_name').attr('required', false); + } + + updateDoctorDetails(); +}); + +// Initial load - Edit mode +updateDoctorDetails(); +