@php use App\Models\School; use App\Models\StudentBiodata; use App\Models\SchoolHealthPhysician; use App\Models\NutritionistHistoryEvaluationSection; use App\Models\PsychologistHistoryAssessmentSection; use App\Models\MedicalHistoryEmail; use App\Models\User; use Carbon\Carbon; use App\Models\form_entry; use App\Models\FormData; @endphp @extends('admin.main') @section('content')

Dashboard

Students

Days Since School Collaboration

Reportables Findings

referrals

Emails Sent

@php $schools = School::get()->toArray(); $labels = array_map(function ($school) { return $school['school_name']; // Ensure this matches your field name }, $schools); $labels = array_map(function ($label) { return $label; }, $labels); $labels1 = array_map(function ($school) { return $school['id']; // Ensure this matches your field name }, $schools); $followups = []; $studentCount = []; $UnfollowUps = []; $SchoolName = []; $daysSinceSchoolCreation = []; $PendingfollowUps = []; $detailedDataMap = []; $TotalPhysicanCount = []; $schoolId = 0; $TotalnutritionFollowUps = []; $TotalPsychologistFollowUps = []; $External_referrals = []; $Internal_referrals = []; $schools = School::get()->toArray(); if (!empty($schools)) { foreach ($schools as $school) { $Physicians = []; $schoolId = $school['id']; $school_name = $school['school_name']; $schoolIdArr[] = $schoolId; $schoolStudentCount = StudentBiodata::join('users', 'users.id', '=', 'student_biodata.created_by') ->leftJoin('school_health_physicians', function ($join) { $join->on('school_health_physicians.StudentBiodataId', '=', 'student_biodata.id') ->where('school_health_physicians.deleted', 0); }) ->leftJoin('nutritionist_history_evaluation_sections', function ($join) { $join->on('nutritionist_history_evaluation_sections.StudentBiodataId', '=', 'student_biodata.id') ->where('nutritionist_history_evaluation_sections.deleted', 0); }) ->leftJoin('psychologist_history_assessment_sections', function ($join) { $join->on('psychologist_history_assessment_sections.StudentBiodataId', '=', 'student_biodata.id') ->where('psychologist_history_assessment_sections.deleted', 0); }) ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->where(function ($query) { $query->whereNotNull('school_health_physicians.StudentBiodataId') ->orWhereNotNull('nutritionist_history_evaluation_sections.StudentBiodataId') ->orWhereNotNull('psychologist_history_assessment_sections.StudentBiodataId'); }); // Debug SQL query before execution // Execute the count $schoolStudentCount = $schoolStudentCount->count(); $studentCount[] = $schoolStudentCount; $studentIds = StudentBiodata::where('School_Name', $schoolId)->where('deleted', 0)->limit(25)->get()->toArray(); $totalFollowUps = 0; $totalUnFollowUps = 0; $totalPendingFollowUps = 0; $TotalPhysicanFollowUps = 0; $TotalnutritionFollowUps1 = 0; $TotalpsychologistFollowUps1 = 0; $TotalInternal_referrals = 0; $TotalExternal_referrals = 0; $Blood_pressure_result_count = 0; $BloodPressureDiastolicResultCount = 0; $TemperatureResultCount = 0; $PulseResultCount = 0; $RespiratoryRateResultCount = 0; $HeightResultCount = 0; $BMIResultCount = 0; $HeightResult1Count = 0; $WeightResult1Count = 0; $BMIResult1Count = 0; $schoolFollowUps = StudentBiodata::join('school_health_physicians', 'school_health_physicians.StudentBiodataId', '=', 'student_biodata.id') ->where('school_health_physicians.deleted', 0) ->where('school_health_physicians.Follow_up_Required', 'Yes') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); $nutritionFollowUps = StudentBiodata::join('nutritionist_history_evaluation_sections', 'nutritionist_history_evaluation_sections.StudentBiodataId', '=', 'student_biodata.id') ->where('nutritionist_history_evaluation_sections.deleted', 0) ->where('nutritionist_history_evaluation_sections.Follow_up_Required1', 'Yes') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); /*$nutritionFollowUps = NutritionistHistoryEvaluationSection::where('deleted', 0) ->where('Follow_up_Required1', 'Yes') ->where('StudentBiodataId', $StudentBiodataId) ->count();*/ $psychologistFollowUps = StudentBiodata::join('psychologist_history_assessment_sections', 'psychologist_history_assessment_sections.StudentBiodataId', '=', 'student_biodata.id') ->where('psychologist_history_assessment_sections.deleted', 0) ->where('psychologist_history_assessment_sections.Follow_up_Required2', 'Yes') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); /*PsychologistHistoryAssessmentSection::where('deleted', 0) ->where('Follow_up_Required2', 'Yes') ->where('StudentBiodataId', $StudentBiodataId) ->count();*/ $totalFollowUps += $schoolFollowUps + $nutritionFollowUps + $psychologistFollowUps; $TotalPhysicanFollowUps += $schoolFollowUps; $TotalnutritionFollowUps1 += $nutritionFollowUps; $TotalpsychologistFollowUps1 += $psychologistFollowUps; /* $schoolUnFollowUps = StudentBiodata::join('school_health_physicians', 'school_health_physicians.StudentBiodataId', '=', 'student_biodata.id') ->where('school_health_physicians.deleted', 0) ->where('school_health_physicians.Follow_up_Required', 'No') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); $nutritionUnFollowUps = StudentBiodata::join('nutritionist_history_evaluation_sections', 'nutritionist_history_evaluation_sections.StudentBiodataId', '=', 'student_biodata.id') ->where('nutritionist_history_evaluation_sections.deleted', 0) ->where('nutritionist_history_evaluation_sections.Follow_up_Required1', 'No') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); $psychologistUnFollowUps = StudentBiodata::join('psychologist_history_assessment_sections', 'psychologist_history_assessment_sections.StudentBiodataId', '=', 'student_biodata.id') ->where('psychologist_history_assessment_sections.deleted', 0) ->where('psychologist_history_assessment_sections.Follow_up_Required2', 'No') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); $totalUnFollowUps += $schoolUnFollowUps + $nutritionUnFollowUps + $psychologistUnFollowUps;*/ $schoolFollowUpsInternal_referrals = StudentBiodata::join('school_health_physicians', 'school_health_physicians.StudentBiodataId', '=', 'student_biodata.id') ->where('school_health_physicians.deleted', 0) ->where('school_health_physicians.Follow_up_Required', 'Yes') ->where('school_health_physicians.internal_referrals', '!=', null) ->where('school_health_physicians.internal_referrals', '!=', '') ->where('school_health_physicians.internal_referrals', '!=', 'Not Required') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); $nutritionFollowUpsInternal_referrals = StudentBiodata::join('nutritionist_history_evaluation_sections', 'nutritionist_history_evaluation_sections.StudentBiodataId', '=', 'student_biodata.id') ->where('nutritionist_history_evaluation_sections.deleted', 0) ->where('nutritionist_history_evaluation_sections.Follow_up_Required1', 'Yes') ->where('nutritionist_history_evaluation_sections.internal_referrals1', '!=', null) ->where('nutritionist_history_evaluation_sections.internal_referrals1', '!=', '') ->where('nutritionist_history_evaluation_sections.internal_referrals1', '!=', 'Not Required') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); $psychologistFollowUpsInternal_referrals = StudentBiodata::join('psychologist_history_assessment_sections', 'psychologist_history_assessment_sections.StudentBiodataId', '=', 'student_biodata.id') ->where('psychologist_history_assessment_sections.deleted', 0) ->where('psychologist_history_assessment_sections.Follow_up_Required2', 'Yes') ->where('psychologist_history_assessment_sections.internal_referrals2', '!=', null) ->where('psychologist_history_assessment_sections.internal_referrals2', '!=', '') ->where('psychologist_history_assessment_sections.internal_referrals2', '!=', 'Not Required') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); $TotalInternal_referrals += $schoolFollowUpsInternal_referrals + $nutritionFollowUpsInternal_referrals + $psychologistFollowUpsInternal_referrals; $schoolFollowUpsExternal_referrals = StudentBiodata::join('school_health_physicians', 'school_health_physicians.StudentBiodataId', '=', 'student_biodata.id') ->where('school_health_physicians.deleted', 0) ->where('school_health_physicians.Follow_up_Required', 'Yes') ->where('school_health_physicians.external_referrals', '!=', null) ->where('school_health_physicians.external_referrals', '!=', '') ->where('school_health_physicians.external_referrals', '!=', 'Not Required') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); $nutritionFollowUpsExternal_referrals = StudentBiodata::join('nutritionist_history_evaluation_sections', 'nutritionist_history_evaluation_sections.StudentBiodataId', '=', 'student_biodata.id') ->where('nutritionist_history_evaluation_sections.deleted', 0) ->where('nutritionist_history_evaluation_sections.Follow_up_Required1', 'Yes') ->where('nutritionist_history_evaluation_sections.external_referrals1', '!=', null) ->where('nutritionist_history_evaluation_sections.external_referrals1', '!=', '') ->where('nutritionist_history_evaluation_sections.external_referrals1', '!=', 'Not Required') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); $psychologistFollowUpsExternal_referrals = StudentBiodata::join('psychologist_history_assessment_sections', 'psychologist_history_assessment_sections.StudentBiodataId', '=', 'student_biodata.id') ->where('psychologist_history_assessment_sections.deleted', 0) ->where('psychologist_history_assessment_sections.Follow_up_Required2', 'Yes') ->where('psychologist_history_assessment_sections.external_referrals2', '!=', null) ->where('psychologist_history_assessment_sections.external_referrals2', '!=', '') ->where('psychologist_history_assessment_sections.external_referrals2', '!=', 'Not Required') ->where('student_biodata.School_Name', $schoolId) ->where('student_biodata.deleted', 0) ->count(); $TotalExternal_referrals += $schoolFollowUpsExternal_referrals + $nutritionFollowUpsExternal_referrals + $psychologistFollowUpsExternal_referrals; if (!empty($studentIds)) { foreach ($studentIds as $key => $value) { $StudentBiodataId = $value['id']; $schoolPendingFollowUps = SchoolHealthPhysician::where('deleted', 0) ->where('Follow_up_Required', 'Yes') ->where('StudentBiodataId', $StudentBiodataId) ->where('Follow_up_Date', '>=', Carbon::today()) ->count(); $nutritionPendingFollowUps = NutritionistHistoryEvaluationSection::where('deleted', 0) ->where('Follow_up_Required1', 'Yes') ->where('StudentBiodataId', $StudentBiodataId) ->where('Follow_up_Date1', '>=', Carbon::today()) ->count(); $psychologistPendingFollowUps = PsychologistHistoryAssessmentSection::where('deleted', 0) ->where('Follow_up_Required2', 'Yes') ->where('StudentBiodataId', $StudentBiodataId) ->where('Follow_up_Date2', '>=', Carbon::today()) ->count(); $totalPendingFollowUps += $schoolPendingFollowUps + $nutritionPendingFollowUps + $psychologistPendingFollowUps; /*$schoolFollowUps1 = SchoolHealthPhysician::where('deleted', 0) ->where('StudentBiodataId', $StudentBiodataId) ->count(); $nutritionFollowUps1 = NutritionistHistoryEvaluationSection::where('deleted', 0) ->where('StudentBiodataId', $StudentBiodataId) ->count(); $psychologistFollowUps1 = PsychologistHistoryAssessmentSection::where('deleted', 0) ->where('StudentBiodataId', $StudentBiodataId) ->count(); */ // echo "StudentBiodataId ".$StudentBiodataId.'
'; $SchoolHealthPhysician1 = SchoolHealthPhysician::where('deleted', 0) ->where('StudentBiodataId', $StudentBiodataId) ->first(); // dd($SchoolHealthPhysician1); if (!empty($SchoolHealthPhysician1)) { $Blood_pressure_result = $SchoolHealthPhysician1['Blood_pressure_result']; if ($Blood_pressure_result == 'Low') { $Blood_pressure_result_count += 1; } else { $Blood_pressure_result_count += 0; } $BloodPressureDiastolicResult = $SchoolHealthPhysician1['BloodPressureDiastolicResult']; if ($BloodPressureDiastolicResult == 'Low') { $BloodPressureDiastolicResultCount += 1; } else { $BloodPressureDiastolicResultCount += 0; } $TemperatureResult = $SchoolHealthPhysician1['TemperatureResult']; if ($TemperatureResult == 'Low') { $TemperatureResultCount += 1; } else { $TemperatureResultCount += 0; } $PulseResult = $SchoolHealthPhysician1['PulseResult']; if ($PulseResult == 'Low') { $PulseResultCount += 1; } else { $PulseResultCount += 0; } $RespiratoryRateResult = $SchoolHealthPhysician1['RespiratoryRateResult']; if ($RespiratoryRateResult == 'Low') { $RespiratoryRateResultCount += 1; } else { $RespiratoryRateResultCount += 0; } $HeightResult = $SchoolHealthPhysician1['HeightResult']; if ($HeightResult == 'Low') { $HeightResultCount += 1; } else { $HeightResultCount += 0; } $BMIResult = $SchoolHealthPhysician1['BMIResult']; if ($BMIResult == 'Low') { $BMIResultCount += 1; } else { $BMIResultCount += 0; } } $NutritionistHistoryEvaluationSection1 = NutritionistHistoryEvaluationSection::where( 'deleted', 0, ) ->where('StudentBiodataId', $StudentBiodataId) ->first(); if (!empty($NutritionistHistoryEvaluationSection1)) { $HeightResult1 = $NutritionistHistoryEvaluationSection1['HeightResult1']; if ($HeightResult1 == 'Low') { $HeightResult1Count += 1; } else { $HeightResult1Count += 0; } $WeightResult1 = $NutritionistHistoryEvaluationSection1['WeightResult1']; if ($WeightResult1 == 'Low') { $WeightResult1Count += 1; } else { $WeightResult1Count += 0; } $BMIResult1 = $NutritionistHistoryEvaluationSection1['BMIResult1']; if ($BMIResult1 == 'Low') { $BMIResult1Count += 1; } else { $BMIResult1Count += 0; } } } $Physicians[] = $Blood_pressure_result_count; $Physicians[] = $BloodPressureDiastolicResultCount; $Physicians[] = $PulseResultCount; $Physicians[] = $TemperatureResultCount; $Physicians[] = $RespiratoryRateResultCount; $Physicians[] = $HeightResultCount; $Physicians[] = $BMIResultCount; $NutritionistGraph[] = $HeightResult1Count; $NutritionistGraph[] = $WeightResult1Count; $NutritionistGraph[] = $BMIResult1Count; } $detailedDataMap[$school_name] = $Physicians; $detailedDataMap1[$school_name] = $NutritionistGraph; $followups[] = $totalFollowUps; $UnfollowUps[] = $totalUnFollowUps; $PendingfollowUps[] = $totalPendingFollowUps; $TotalPhysicanCount[] = $TotalPhysicanFollowUps; $TotalnutritionFollowUps[] = $TotalnutritionFollowUps1; $TotalPsychologistFollowUps[] = $TotalpsychologistFollowUps1; $Internal_referrals[] = $TotalInternal_referrals; $External_referrals[] = $TotalExternal_referrals; } } $schools = School::all()->toArray(); if (!empty($schools)) { foreach ($schools as $index => $school) { $School = $school['school_name']; $School_id = $school['id']; $createdAt = $school['created_at']; $daysSince = now()->diffInDays($createdAt); $daysSinceSchoolCreation[] = $daysSince; $SchoolName[] = $School; } } $findings = DB::table('student_biodata') ->select('School_Name', DB::raw('COUNT(id) as count')) ->groupBy('School_Name') ->having(DB::raw('COUNT(id)'), '>', 1) ->get() ->toArray(); $schools1 = School::all(); // Adjust the query to get the data you need // Define an array of colors to use for the chart $colors = [ ['borderColor' => 'rgba(255,99,132,1)', 'backgroundColor' => 'rgba(255,99,132,0.2)'], // Red ['borderColor' => 'rgba(54,162,235,1)', 'backgroundColor' => 'rgba(54,162,235,0.2)'], // Blue ['borderColor' => 'rgba(255,206,86,1)', 'backgroundColor' => 'rgba(255,206,86,0.2)'], // Yellow ['borderColor' => 'rgba(75,192,192,1)', 'backgroundColor' => 'rgba(75,192,192,0.2)'], // Green ['borderColor' => 'rgba(153,102,255,1)', 'backgroundColor' => 'rgba(153,102,255,0.2)'], // Purple ['borderColor' => 'rgba(255,159,64,1)', 'backgroundColor' => 'rgba(255,159,64,0.2)'], // Orange // Add more colors as needed ]; $schoolData = $schools1->map(function ($school, $index) use ($colors) { // Initialize an array with 12 zeros to represent counts for each month (Jan to Dec) $monthlyCounts = array_fill(0, 12, 0); // Fetch all MedicalHistoryEmails for the school and group by month $emails = MedicalHistoryEmail::where('to', $school->email) ->selectRaw('MONTH(created_at) as month, COUNT(*) as count') ->groupBy('month') ->limit(25) ->get(); // Populate the monthlyCounts array with actual counts foreach ($emails as $email) { $monthIndex = $email->month - 1; // Convert month to zero-based index $monthlyCounts[$monthIndex] = $email->count; } // Use a predefined color or a random color if the index exceeds the array size $color = $colors[$index % count($colors)]; return [ 'label' => $school->school_name, 'backgroundColor' => $color['backgroundColor'], 'borderColor' => $color['borderColor'], 'borderWidth' => 2, 'data' => $monthlyCounts, // Array of counts for each month ]; }); /* // Prepare the data to be used in the chart (this assumes each school has 'name' and 'data' fields) $schoolData = $schools1->map(function ($school) { $monthlyCounts = array_fill(0, 12, 0); $emails = MedicalHistoryEmail::where('to', $school->email) ->selectRaw('MONTH(created_at) as month, COUNT(*) as count') ->groupBy('month') ->get(); foreach ($emails as $email) { $monthIndex = $email->month - 1; // Convert month to zero-based index $monthlyCounts[$monthIndex] = $email->count; } return [ 'label' => $school->school_name, 'backgroundColor' => 'rgba(135,206,250,0.2)', // Lightblue with transparency 'borderColor' => 'blue', 'borderWidth' => 2, // 'data' => json_decode($school->data), // Assuming 'data' field is a JSON encoded array // 'data' => [175, 180, 190, 170, 160, 175, 190, 200, 180, 195, 180, 190] 'data' => $monthlyCounts // Array of counts for each month ]; }); */ $screenedData = []; $unscreenedData = []; $schools2 = School::get()->toArray(); // Adjust the query to get the data you need if (!empty($schools2)) { foreach ($schools2 as $key => $value) { $schools2ID = $value['id']; // echo ' schools2ID ' . $schools2ID . '
'; $entriesCount[] = form_entry::where('school', $schools2ID)->count(); $entries = form_entry::where('school', $schools2ID) ->limit(25) // Add a limit of 10 entries ->get() ->toArray(); $Question_No_1_Height_count_grand = 0; $Question_No_1_Height_count_1_grand = 0; $Question_No_1_Height_count = form_entry::join('form_data','form_data.entry_id','=','form_entries.id') ->where('form_data.key', 'Question_No_1_Height') ->where('form_entries.school', $schools2ID) ->count(); $Question_No_1_Height_count_grand += $Question_No_1_Height_count; $Question_No_1_Height_count_1 =form_entry::join('form_data','form_data.entry_id','=','form_entries.id') ->where('form_data.key', 'Question_No_1_Height') ->where('form_data.value', '') ->where('form_data.value', null) ->where('form_entries.school', $schools2ID) ->count(); $Question_No_1_Height_count_1_grand += $Question_No_1_Height_count_1; /* if (!empty($entries)) { foreach ($entries as $entry) { $entriesID = $entry['id']; } }*/ $screenedData[] = $Question_No_1_Height_count_grand; $unscreenedData[] = $Question_No_1_Height_count_1_grand; $questions = [ /* General Apperance */ ['key' => 'Question_No_8_Normal_Posture_Gait', 'label' => 'Posture/Gait', 'value' => 'no'], ['key' => 'Question_No_9_Mental_Status', 'label' => 'Mental Status', 'value' => 'Lethargic'], ['key' => 'Question_No_10_Look_For_jaundice', 'label' => 'Jaundice', 'value' => 'yes'], ['key' => 'Question_No_11_Look_For_anemia', 'label' => 'Anemia', 'value' => 'yes'], ['key' => 'Question_No_12_Look_For_Clubbing', 'label' => 'Clubbing', 'value' => 'yes'], ['key' => 'Question_No_13_Look_for_Cyanosis', 'label' => 'Cyanosis', 'value' => 'yes'], ['key' => 'Question_No_14_Skin', 'label' => 'Skin', 'value' => ['rash', 'allergy', 'lesion', 'bruises', 'Bad Breath']], ['key' => 'Question_No_15_Breath', 'label' => 'Breath', 'value' => 'Bad Breath'], /* Inspect Hygiene */ ['key' => 'Question_No_16_Nails', 'label' => 'Nails', 'value' => 'dirty'], ['key' => 'Question_No_17_Uniform_or_shoes', 'label' => 'Uniform or Shoes', 'value' => 'untidy'], ['key' => 'Question_No_18_Lice/nits', 'label' => 'Lice/Nits', 'value' => 'yes'], ['key' => 'Question_No_19_Discuss_hygiene_routines_and_practices', 'label' => 'Hygiene Routines and Practices', 'value' => 'not-aware'], /* Head and Neck Examination */ ['key' => 'Question_No_20_Hair_and_Scalp', 'label' => 'Hair and Scalp', 'value' => 'Color-faded'], ['key' => 'Question_No_21_Any_Hair_Problem', 'label' => 'Hair Problem', 'value' => ['Dry', 'Kinky', 'Brittle']], ['key' => 'Question_No_22_Scalp', 'label' => 'Scalp', 'value' => ['Dry', 'Scaly', 'Moist']], ['key' => 'Question_No_23_Hair_Distribution', 'label' => 'Hair Distribution', 'value' => ['Patchy', 'Receding', 'Receding_hair_line']], /* Eye Examination */ ['key' => 'Question_No_25_Normal_ocular_alignment', 'label' => 'Ocular Alignment', 'value' => 'no'], ['key' => 'Question_No_26_Normal_eye_inspection', 'label' => 'Eye Inspection', 'value' => 'no'], ['key' => 'Question_No_28_Nystagmus', 'label' => 'Nystagmus', 'value' => 'yes'], /* Ears */ ['key' => 'Question_No_29_Normal_ears_shape_and_position', 'label' => ' Ears Shape and Position', 'value' => 'no'], ['key' => 'Question_No_30_Ear_examination', 'label' => ' Ear Examination', 'value' => ['Ear wax', 'Canal Infection']], ['key' => 'Question_No_31_Conclusion_of_hearing_test_with_Rinner_and_Weber', 'label' => ' Conclusion of Hearing Test', 'value' => ['right_ear_conductive_hearing_loss', 'left_ear_conductive_hearing_loss', 'right_sensorineural_loss', 'left_sensorineural_loss']], /* Nose */ ['key' => 'Question_No_32_External_nasal_examinaton', 'label' => ' External Nasal Examination', 'value' => ['deformities', 'swelling', 'redness', 'lesions', 'Nasal Discharge']], ['key' => 'Question_No_33_perform_a_nasal_patency_test_which_involves_gently_closing_one_nostril_at_a_time_to_assess_the_patients_ability_to_breathe_through_each_nostril', 'label' => ' Nasal Patency Test', 'value' => ['obstruction', 'dns']], /* Oral */ ['key' => 'Question_No_34_Assess_gingiva', 'label' => ' Assess Gingiva', 'value' => ['Infection', 'bleed']], ['key' => 'Question_No_35_Are_there_dental_caries', 'label' => ' Are There Dental Caries', 'value' => 'yes'], /* Throat */ ['key' => 'Question_No_36_Examine_tonsils', 'label' => ' Examine Tonsils', 'value' => 'tonsillitis'], ['key' => 'Question_No_37_Normal_Speech_development', 'label' => ' Speech Development', 'value' => 'no'], ['key' => 'Question_No_38_Any_Neck_swelling', 'label' => ' Neck Swelling', 'value' => 'yes'], ['key' => 'Question_No_39_Examine_lymph_node', 'label' => ' Examine Lymph Node', 'value' => 'abnormal'], /* Chest */ ['key' => 'Question_No_40_Any_visible_chest_deformity', 'label' => ' Visible Chest Deformity', 'value' => 'yes'], ['key' => 'Question_No_41_Lung_Auscultation', 'label' => ' Lung Auscultation', 'value' => ['wheezing', 'crackles']], ['key' => 'Question_No_42_Cardiac_Auscultation', 'label' => ' Cardiac Auscultation', 'value' => 'murmur'], /* Abdomen */ ['key' => 'Question_No_43_Did_you_observe_any_distension,_scars,_or_masses_on_the_childs_abdomen?', 'label' => ' Distension/Scars/Masses on Abdomen', 'value' => ['distension', 'scar', 'mass']], /* Musculoskeletal */ ['key' => 'Question_No_45_Did_you_observe_any_limitations_in_the_child_s_range_of_joint_motion_during_your_examination', 'label' => ' Limitations in Joint Motion', 'value' => 'yes'], ['key' => 'Question_No_46_Spinal_curvature_assessment_tick_positive_finding', 'label' => ' Spinal Curvature Assessment', 'value' => ['uneven shoulder', 'shoulder blade', 'uneven waist', 'Hips']], ['key' => 'Question_No_47_side_to_side_curvature_in_the_spine_resembling', 'label' => ' Side-to-Side Curvature', 'value' => ['c_shape', 's_shape']], ['key' => 'Question_No_48_Adams_forward_bend_test', 'label' => ' Adams Forward Bend Test', 'value' => 'positive'], ['key' => 'Question_No_49_Any_foot_or_toe_abnormalities', 'label' => ' Foot or Toe Abnormalities', 'value' => ['flat feet', 'varus', 'valgus', 'high arch', 'hammer toe', 'bunion']], ]; $PresentingComplains = form_entry::join('form_data', 'form_data.entry_id', '=', 'form_entries.id') ->where('form_entries.school', $schools2ID) ->where(function ($query) use ($questions) { foreach ($questions as $question) { if (is_array($question['value'])) { // If value is an array, use `whereIn` $query->orWhere(function ($subQuery) use ($question) { $subQuery->where('form_data.key', $question['key']) ->whereIn('form_data.value', $question['value']); }); } else { // If value is a single string, use `where` $query->orWhere(function ($subQuery) use ($question) { $subQuery->where('form_data.key', $question['key']) ->where('form_data.value', $question['value']); }); } } }) ->count(); } } @endphp @endsection