@php
use App\Models\User;
use App\Models\form_entry;
use App\Models\FormData;
@endphp
@extends('admin.main')
@section('content')
{{-- --}}
@php
/* Student Questions */
$questions = [
[
'key' => 'Question_No_8_Normal_Posture/Gait',
'label' => 'Question No.8: Normal Posture/Gait',
'value' => 'yes',
],
[
'key' => 'Question_No_9_Mental_Status',
'label' => 'Question No.9: Mental Status',
'value' => 'Lethargic',
],
[
'key' => 'Question_No_10_Look_For_jaundice',
'label' => 'Question No.10: Look For Jaundice',
'value' => 'yes',
],
];
$questionLabels = [];
$answers = [];
/* School Role = 3 */
$form_entry_count = 0;
$ScreenedStudentsCount = 0;
$UnScreenedStudentsCount = 0;
$UsersRoles = User::where('role', 3)
->where('id', auth()->guard('admin')->user()->id)
->first();
if (!empty($UsersRoles)) {
$UsersRoleSchoolID = $UsersRoles['school_id'];
$schoolIDsArray = json_decode($UsersRoleSchoolID, true);
if (!empty($schoolIDsArray)) {
foreach ($schoolIDsArray as $key => $value) {
$form_entry_count += form_entry::where('school', $value)->count();
$ScreenedStudentsCount += form_entry::where('school', $value)
->where('Follow_up_Date_flag', 1)
->count();
$UnScreenedStudentsCount += form_entry::where('school', $value)
->where('Follow_up_Date_flag', 0)
->count();
/* Student Questions */
/*foreach ($questions as $key => $question) {
$query = FormData::join('form_entries', 'form_data.entry_id', '=', 'form_entries.id')
->where('form_data.key', $question['key'])
->where('form_entries.school', $value);
if (is_array($question['value'])) {
$count = $query->whereIn('value', $question['value'])->count();
} elseif ($question['value'] !== null) {
$count = $query->where('value', $question['value'])->count();
} elseif ($question['value'] == null) {
$count = $query->where('value', $question['value'])->count();
} else {
$count = $query->count();
}
$questionLabels[] = $question['label'];
$answers[] = $count;
}*/
}
}
}
/* Student Questions */
$Question_No_8_Normal_Posture_Gait = FormData::join(
'form_entries',
'form_data.entry_id',
'=',
'form_entries.id',
)->where('form_data.key', 'Question_No_8_Normal_Posture/Gait');
$Question_No_8_Normal_Posture_Gait = $Question_No_8_Normal_Posture_Gait->where('value', 'No')->count();
foreach ($questions as $key => $question) {
$query = FormData::join('form_entries', 'form_data.entry_id', '=', 'form_entries.id')->where(
'form_data.key',
$question['key'],
);
if (is_array($question['value'])) {
$count = $query->whereIn('value', $question['value'])->count();
} elseif ($question['value'] !== null) {
$count = $query->where('value', $question['value'])->count();
} elseif ($question['value'] == null) {
$count = $query->where('value', $question['value'])->count();
} else {
$count = $query->count();
}
$questionLabels[] = $question['label'];
$answers[] = $count;
}
@endphp
@endsection