From 957beb7ae02bfd2fdae236b48b7f546355f0d801 Mon Sep 17 00:00:00 2001 From: Ravi Gulhane Date: Wed, 7 Oct 2026 15:04:53 +0530 Subject: [PATCH] Let the Doctor and Chemist survey open saved answers from History and keep the shared form on edit. Co-authored-by: Cursor --- app/Http/Controllers/FormController.php | 64 +++++- ...9-4ac0-9b18-6d366a74965e-history.blade.php | 99 ++++++++++ ...58a6-d509-4ac0-9b18-6d366a74965e.blade.php | 182 +++++++++++++++++- .../partials/doctor-chemist-chemist.blade.php | 12 +- .../partials/doctor-chemist-doctor.blade.php | 12 +- 5 files changed, 340 insertions(+), 29 deletions(-) create mode 100644 resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e-history.blade.php diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index c6d0f615..57c1dda8 100644 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -56,6 +56,13 @@ class FormController extends Controller return $value === true || $value === 1 || $value === '1' || $value === 'true'; } + protected function doctorChemistBladeId($formId) { + if ($formId === '1790230856-704c97b6-61f7-4eda-901a-2cb4ff6f293d') { + return '1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e'; + } + return $formId; + } + protected function deliverform($formdata, $questions, $id = false) { $additional_info = $this->get_additional_info($formdata); // if($formdata->form_id == '1711609582-e93dba24-9c98-43e7-b97a-b22d64d9b9fc') { @@ -91,10 +98,11 @@ class FormController extends Controller // return view('form.common', $data); // } - if (\View::exists('form.'.$formdata->partition.'.'.$formdata->form_id)) { - return view('form.'.$formdata->partition.'.'.$formdata->form_id)->with($data); - } elseif (\View::exists('form.'.$formdata->form_id)) { - return view('form.'.$formdata->form_id)->with($data); + $viewId = $this->doctorChemistBladeId($formdata->form_id); + if (\View::exists('form.'.$formdata->partition.'.'.$viewId)) { + return view('form.'.$formdata->partition.'.'.$viewId)->with($data); + } elseif (\View::exists('form.'.$viewId)) { + return view('form.'.$viewId)->with($data); } elseif(isset($formdata->form_type) && $formdata->form_type == 'enrollment_form'){ return view('form.common-enrollmentform', $data); } elseif(isset($formdata->form_type) && $formdata->form_type == 'plan_vs_execution'){ @@ -563,6 +571,11 @@ class FormController extends Controller public function show(Request $request) { $formdata = $request->session()->get('formdata'); //Log::debug(print_r($formdata, true)); + $requestedFormId = $request->input('form_id', ''); + if (is_string($requestedFormId) && $requestedFormId !== '') { + $formdata->form_id = $requestedFormId; + $request->session()->put('formdata', $formdata); + } $id = $request->input('id', false); $action = $request->input('action', false); Log::debug(print_r(['form_id' => $formdata->form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition, 'id' => $id ], true)); @@ -8345,6 +8358,34 @@ class FormController extends Controller $data['incept_neb'] = $inceptService->withOrgTotals([], $formdata); } + $doctorSurveyId = '1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e'; + $chemistSurveyId = '1790230856-704c97b6-61f7-4eda-901a-2cb4ff6f293d'; + if (in_array($form_id, [$doctorSurveyId, $chemistSurveyId], true)) { + $loadHistory = function ($id) use ($formdata, $form_id, $history) { + if ($id === $form_id) { + return $history; + } + return LambdaRequest::postrequest('form', 'formentity/getformhistory', ['form_id' => $id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition]); + }; + $doctorHistory = $loadHistory($doctorSurveyId); + $chemistHistory = $loadHistory($chemistSurveyId); + $historyRows = function ($response) { + return [ + 'questions' => isset($response->data->questions) ? $response->data->questions : [], + 'submissions' => isset($response->data->submissions) ? $response->data->submissions : [], + ]; + }; + $doctorRows = $historyRows($doctorHistory); + $chemistRows = $historyRows($chemistHistory); + $data['doctor_form_id'] = $doctorSurveyId; + $data['chemist_form_id'] = $chemistSurveyId; + $data['doctor_questions'] = $doctorRows['questions']; + $data['doctor_submissions'] = $doctorRows['submissions']; + $data['chemist_questions'] = $chemistRows['questions']; + $data['chemist_submissions'] = $chemistRows['submissions']; + return view('form.'.$formdata->partition.'.'.$doctorSurveyId.'-history')->with($data); + } + if (\View::exists('form.'.$formdata->partition.'.'.$formdata->form_id.'-history')) { return view('form.'.$formdata->partition.'.'.$formdata->form_id.'-history')->with($data); } elseif (\View::exists('form.'.$formdata->form_id.'-history')) { @@ -8359,15 +8400,22 @@ class FormController extends Controller public function edit(Request $request) { $formdata = $request->session()->get('formdata'); //Log::debug(print_r($formdata, true)); + $requestedFormId = $request->input('form_id', ''); + if (is_string($requestedFormId) && $requestedFormId !== '') { + $formdata->form_id = $requestedFormId; + $request->session()->put('formdata', $formdata); + } $id = $request->input('id', false); //'user_id' => $formdata->user_id, $finfo = LambdaRequest::postrequest('form', 'formentity/getformdefination', ['form_id' => $formdata->form_id, 'partition' => $formdata->partition, 'id' => $id ]); $formdata->title = $finfo->data->formdata->title; + $formdata->formdata = $finfo->data->formdata; //Log::debug(print_r($finfo->data->formdata, true)); - if (\View::exists('form.'.$formdata->partition.'.'.$formdata->form_id)) { - return view('form.'.$formdata->partition.'.'.$formdata->form_id)->with(['questions' => $finfo->data->questions,'form_id' => $formdata->form_id, 'form' => $formdata, 'id' => $id, 'formdata' => $finfo->data->formdata ]); - } elseif (\View::exists('form.'.$formdata->form_id)) { - return view('form.'.$formdata->form_id)->with(['questions' => $finfo->data->questions,'form_id' => $formdata->form_id, 'form' => $formdata, 'id' => $id, 'formdata' => $finfo->data->formdata ]); + $viewId = $this->doctorChemistBladeId($formdata->form_id); + if (\View::exists('form.'.$formdata->partition.'.'.$viewId)) { + return view('form.'.$formdata->partition.'.'.$viewId)->with(['questions' => $finfo->data->questions,'form_id' => $formdata->form_id, 'form' => $formdata, 'id' => $id, 'formdata' => $finfo->data->formdata ]); + } elseif (\View::exists('form.'.$viewId)) { + return view('form.'.$viewId)->with(['questions' => $finfo->data->questions,'form_id' => $formdata->form_id, 'form' => $formdata, 'id' => $id, 'formdata' => $finfo->data->formdata ]); } else { return view('form.common')->with(['questions' => $finfo->data->questions, 'form_id' => $formdata->form_id, 'form' => $formdata, 'id' => $id, 'formdata' => $finfo->data->formdata ]); } diff --git a/resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e-history.blade.php b/resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e-history.blade.php new file mode 100644 index 00000000..8389b009 --- /dev/null +++ b/resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e-history.blade.php @@ -0,0 +1,99 @@ + + + + @include('layouts.shared/title-meta', ['title' => 'History']) + @include('layouts.shared/head-css', ['mode' => $mode ?? '', 'demo' => $demo ?? '']) + + + + @include('layouts.shared/footer-script') + + diff --git a/resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e.blade.php b/resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e.blade.php index f3141221..b9d26500 100644 --- a/resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e.blade.php +++ b/resources/views/form/rapport-team3/1790230856-a5ff58a6-d509-4ac0-9b18-6d366a74965e.blade.php @@ -42,7 +42,8 @@
@csrf - + +
@@ -73,6 +74,33 @@
@include('layouts.shared/footer-script') +@php + $savedAnswers = []; + $savedSource = null; + if (!empty($id)) { + if (isset($formdata) && (is_object($formdata) || is_array($formdata))) { + $savedSource = $formdata; + } elseif (isset($form->formdata)) { + $savedSource = $form->formdata; + } + } + if (is_object($savedSource) || is_array($savedSource)) { + foreach ((array) $savedSource as $savedKey => $savedValue) { + if ($savedKey === 'title' || is_array($savedValue) || is_object($savedValue) || $savedValue === null || $savedValue === '') { + continue; + } + $savedAnswers[$savedKey] = $savedValue; + } + } + foreach (($questions ?? []) as $savedQuestion) { + if (!is_object($savedQuestion) || empty($savedQuestion->code)) { + continue; + } + if (!isset($savedAnswers[$savedQuestion->code]) && isset($savedQuestion->value) && $savedQuestion->value !== '' && !is_array($savedQuestion->value) && !is_object($savedQuestion->value)) { + $savedAnswers[$savedQuestion->code] = $savedQuestion->value; + } + } +@endphp diff --git a/resources/views/form/rapport-team3/partials/doctor-chemist-chemist.blade.php b/resources/views/form/rapport-team3/partials/doctor-chemist-chemist.blade.php index e2266d79..7c7e98ed 100644 --- a/resources/views/form/rapport-team3/partials/doctor-chemist-chemist.blade.php +++ b/resources/views/form/rapport-team3/partials/doctor-chemist-chemist.blade.php @@ -28,14 +28,14 @@ $services = ['BP Monitoring' => 'chemist_bp_monitoring','Weighing Machine' => 'c -
+
-
+
-
+
@foreach($products as $label => $code) @@ -72,7 +72,7 @@ $services = ['BP Monitoring' => 'chemist_bp_monitoring','Weighing Machine' => 'c
-
+
@foreach([1,2] as $n) @@ -86,7 +86,7 @@ $services = ['BP Monitoring' => 'chemist_bp_monitoring','Weighing Machine' => 'c
-
+
@foreach($therapies as $label => $code) @@ -95,7 +95,7 @@ $services = ['BP Monitoring' => 'chemist_bp_monitoring','Weighing Machine' => 'c
-
+
@foreach($services as $label => $code) diff --git a/resources/views/form/rapport-team3/partials/doctor-chemist-doctor.blade.php b/resources/views/form/rapport-team3/partials/doctor-chemist-doctor.blade.php index d9984765..bb2f16b8 100644 --- a/resources/views/form/rapport-team3/partials/doctor-chemist-doctor.blade.php +++ b/resources/views/form/rapport-team3/partials/doctor-chemist-doctor.blade.php @@ -26,7 +26,7 @@ $products = ['Asthalin Inhaler' => 'asthalin_inhaler','Asthalin Rotacap' => 'ast
-
+
@@ -34,7 +34,7 @@ $products = ['Asthalin Inhaler' => 'asthalin_inhaler','Asthalin Rotacap' => 'ast
-
+
@foreach($products as $label => $code) @@ -43,12 +43,12 @@ $products = ['Asthalin Inhaler' => 'asthalin_inhaler','Asthalin Rotacap' => 'ast
-
+

Upload one of visiting card, Rx pad or doctor board. JPG, JPEG or PNG, max 10 MB.

-
-
-
+
+
+