HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/ghayatcom/ghayatcom-api/app/Http/Requests/SubmitConsultationRequest.php
<?php

namespace App\Http\Requests;

use App\Library\CustomFailedValidation;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Validation\Rule;

class SubmitConsultationRequest extends CustomFailedValidation
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $data = $this->request->all();
        $rules = [];
        if($this->status == 1) {
            $rules['appointment_id'] = 'required|exists:appointments,id';
            $rules['health_record'] = 'required';
            $health_record = json_decode($data['health_record']);
            /**
             * @var object $health_record
             */
            $rules['diagnosis'] = Rule::requiredIf(function() use ($health_record) {
                return (empty($health_record->diagnosis)) ? true : false;
            });

            $rules['treatment_given'] = Rule::requiredIf(function() use ($health_record) {
                return (empty($health_record->treatment_given)) ? true : false;
            });

            $rules['referal'] = 'required';
            $referal = json_decode($data['referal']);
            /**
             * @var object $referal
             */
            $rules['presenting_complaints'] = Rule::requiredIf(function() use ($referal) {
                if($referal->is_referal == 1){
                	return (empty($referal->presenting_complaints)) ? true : false;
                }
            	else {
                	return false;
                }
            });
            if($this->hasFile('patient_certificate')){
                $rules['patient_certificate'] = 'mimes:jpg,jpeg,png,pdf';
            }
            if($this->hasFile('employer_certificate')){
                $rules['patient_certificate'] = 'mimes:jpg,jpeg,png,pdf';
            }
        }
        return $rules;
    }
    public function messages()
    {
        return [
            'appointment_id.required' => __('digimed_validation.form_validation_error.appointment_id_req'),
            'appointment_id.exists' => __('digimed_validation.form_validation_error.appointment_id_is_not_exisit')
        ];
    }
}