From 2deb19db729449d1ad2ca74eff7caa285896873c Mon Sep 17 00:00:00 2001 From: Tanuja Pansare Date: Wed, 4 Nov 2026 14:08:04 +0530 Subject: [PATCH 1/2] Team3 New Form - TOBA TITANS Enrollment --- ...9-4117-b364-e4851e1f4bdf-history.blade.php | 267 ++++++++ ...f040-1469-4117-b364-e4851e1f4bdf.blade.php | 602 ++++++++++++++++++ 2 files changed, 869 insertions(+) create mode 100644 resources/views/form/rapport-team3/1793767249-069bf040-1469-4117-b364-e4851e1f4bdf-history.blade.php create mode 100644 resources/views/form/rapport-team3/1793767249-069bf040-1469-4117-b364-e4851e1f4bdf.blade.php diff --git a/resources/views/form/rapport-team3/1793767249-069bf040-1469-4117-b364-e4851e1f4bdf-history.blade.php b/resources/views/form/rapport-team3/1793767249-069bf040-1469-4117-b364-e4851e1f4bdf-history.blade.php new file mode 100644 index 00000000..25d948ae --- /dev/null +++ b/resources/views/form/rapport-team3/1793767249-069bf040-1469-4117-b364-e4851e1f4bdf-history.blade.php @@ -0,0 +1,267 @@ +@php + $multiDoctorFormId = '1793767249-069bf040-1469-4117-b364-e4851e1f4bdf'; + + $isMultiDoctorForm = isset($form->form_id) + && $form->form_id == $multiDoctorFormId; + + $doctorFieldCodes = [ + 'contact_id', + 'legacy_code', + 'msl_code', + 'speciality' + ]; + + $doctorFieldLabels = [ + 'contact_id' => 'HCP Name', + 'legacy_code' => 'MSL Code', + 'msl_code' => 'Pcode', + 'speciality' => 'Speciality' + ]; +@endphp + + + + @include('layouts.shared/title-meta', ['title' => "History"]) + @include('layouts.shared/head-css', ["mode" => $mode ?? '', "demo" => $demo ?? '']) + + + +
+
+ + +
+
+

{{$formname}}

+
+ +
+ + @if(session()->has('message')) +
+ {{ session()->get('message') }} +
+ @endif + @if(session()->has('error')) +
+ {{ session()->get('error') }} +
+ @endif +
+
+
+
+
+
+
+ + + + + + @if($isMultiDoctorForm) + + @for($i = 1; $i <= 5; $i++) + @foreach($doctorFieldLabels as $code => $label) + + @endforeach + @endfor + + @else + + @foreach($questions as $code => $question) + @if($question->type == 'hidden') + @continue + @endif + + @if($question->type == 'multitextbox') + @foreach($question->options as $k => $v) + + @endforeach + @else + + @endif + @endforeach + + @endif + + + + + + @foreach($submissions as $submission) + + + + @if($isMultiDoctorForm) + + @php + $doctorData = []; + + foreach ($doctorFieldCodes as $code) { + $rawValue = $submission->formdata->{$code} ?? []; + + if (is_string($rawValue)) { + $values = explode(',', $rawValue); + } elseif (is_array($rawValue)) { + $values = $rawValue; + } elseif (is_object($rawValue)) { + $values = (array) $rawValue; + } else { + $values = []; + } + + $doctorData[$code] = array_map( + fn($value) => trim((string) $value), + array_values($values) + ); + } + @endphp + + @for($i = 0; $i < 5; $i++) + + @foreach($doctorFieldCodes as $code) + + + + @endforeach + + @endfor + + @else + + @foreach(($userAttrs ?? []) as $attr) + @php + $uaUser = $submission->user_info ?? null; + $uaVal = '-'; + + if ($uaUser) { + if (isset($uaUser->{$attr}) && $uaUser->{$attr} !== '') { + $uaVal = $uaUser->{$attr}; + } elseif (isset($uaUser->{'attribute_'.$attr}) && $uaUser->{'attribute_'.$attr} !== '') { + $uaVal = $uaUser->{'attribute_'.$attr}; + } + } + @endphp + + + @endforeach + + @foreach($questions as $code => $question) + + @if($question->type == 'hidden') + @continue + @endif + + @if($question->type == 'file') + + + + @elseif($question->type == 'radiometrix' && isset($submission->formdata->{$code}) && is_object($submission->formdata->{$code})) + + + + @elseif($question->type == 'multitextbox') + + @foreach($question->options as $k => $v) + @php + $optKey = is_object($v) ? ($v->value ?? $k) : $k; + $optVal = ''; + + if (isset($submission->formdata->{$optKey})) { + $raw = $submission->formdata->{$optKey}; + $optVal = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw); + } elseif (isset($submission->formdata->{$code}) && (is_object($submission->formdata->{$code}) || is_array($submission->formdata->{$code}))) { + $box = (array) $submission->formdata->{$code}; + + if (array_key_exists($optKey, $box)) { + $raw = $box[$optKey]; + $optVal = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw); + } + } + @endphp + + + @endforeach + + @else + + + + @endif + + @endforeach + + @endif + + + + @endforeach + +
Submission Date + {{ $label }} {{ $i }} + + {{ is_object($v) ? ($v->display ?? $v->label ?? $k) : $v }} + ({{ $question->label }}) + {{ $question->label }}Actions
+ {{ date("d M Y", strtotime($submission->updatedAt)) }} + + {{ $doctorData[$code][$i] ?? '-' }} + {{ $uaVal }} + + Download + + + {{ collect((array)$submission->formdata->{$code})->map(function($val, $key) { + return "$key: $val"; + })->implode(', ') }} + {{ $optVal }} + {{ isset($submission->formdata->{$code}) + ? (is_array($submission->formdata->{$code}) + ? implode(', ', $submission->formdata->{$code}) + : (is_object($submission->formdata->{$code}) + ? collect((array)$submission->formdata->{$code})->map(function($val, $key) { + return "$key: $val"; + })->implode(', ') + : $submission->formdata->{$code})) + : '' }} + + @php + $isApproved = ($submission->workflow ?? '') == 'yes' + && ($submission->workflow_status ?? '') == 'approved'; + + $showFieldDelete = isset($form->allow_delete_by_user) + && $form->allow_delete_by_user == 'yes' + && !$isApproved; + @endphp + + + + @if($showFieldDelete || !empty($can_delete_submission)) + Delete + @endif +
+
+ +
+
+ +
+
+
+
+ +
+ +
+ + @include('layouts.shared/footer-script') + + \ No newline at end of file diff --git a/resources/views/form/rapport-team3/1793767249-069bf040-1469-4117-b364-e4851e1f4bdf.blade.php b/resources/views/form/rapport-team3/1793767249-069bf040-1469-4117-b364-e4851e1f4bdf.blade.php new file mode 100644 index 00000000..54685f23 --- /dev/null +++ b/resources/views/form/rapport-team3/1793767249-069bf040-1469-4117-b364-e4851e1f4bdf.blade.php @@ -0,0 +1,602 @@ + + + + @include('layouts.shared/title-meta', ['title' => "Form"]) + @include('layouts.shared/head-css', ["mode" => $mode ?? '', "demo" => $demo ?? '']) + + +
+ processing... +
+ +
+
+
+
+
+
+ + @if(Session::has('error'))
{{Session::get('error')}}
+
@endif + @if(session('success'))
{{ session('success') }} +
+
@endif +
+

{{$form->title}}

+
+ @if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) ) +
+ @if($form->link_type == 'form') + View History + @else + Back + @endif +
+ @endif + @if(isset($form->user_info)) +
+
Submitted By: {{$form->user_info->name}}
+
+ @endif +
+ + @csrf + @if($id) + + @endif + @if(isset($form->manager_can_submit) && $form->manager_can_submit == true) +
+ + + +
+ @endif + + @php + $multiDoctorFormId = '1793767249-069bf040-1469-4117-b364-e4851e1f4bdf'; + + $doctorFieldCodes = [ + 'contact_id', + 'legacy_code', + 'msl_code', + 'speciality' + ]; + + $doctorQuestions = collect($questions)->keyBy('code'); + @endphp + + @if($form_id == $multiDoctorFormId) + +
+ +
+
Doctor 1
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ + @for($i = 2; $i <= 5; $i++) + + @endfor + + + +
+ + {{-- Render all other questions normally --}} + @foreach($questions as $question) + @if(!in_array($question->code, $doctorFieldCodes)) + +
+ + + @switch($question->type) + + @case('hidden') + + @break + + @case('text') + @case('email') + @case('tel') + @case('date') + required == 'yes'?'required':''}} + value="{{isset($question->value)?$question->value:''}}"> + @break + + @case('number') + required == 'yes'?'required':''}} + value="{{isset($question->value)?$question->value:0}}"> + @break + + @case('textarea') + + @break + + @case('dropdown') + + @break + + @case('radio') + @foreach($question->options as $option) +
+ + +
+ @endforeach + @break + + @case('checkbox') + @foreach($question->options as $option) +
+ + +
+ @endforeach + @break + + @case('file') + required == 'yes'?'required':''}}> + @break + + @endswitch +
+ + @endif + @endforeach + + @else + + {{-- Keep your existing question-rendering code here for all other forms. --}} + + @endif + @if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) ) +
+ +
+ @endif +
+ +
+
+ + + + +
+
+ +
+ +
+ + +@include('layouts.shared/footer-script') + + + + + \ No newline at end of file From b75579f346cdb0a55f95dc5eccc398689668f97b Mon Sep 17 00:00:00 2001 From: Ravi Gulhane Date: Wed, 4 Nov 2026 15:02:22 +0530 Subject: [PATCH 2/2] Changes --- app/Helpers/TgicsHelper.php | 29 ++++++- app/Http/Controllers/FormController.php | 76 +++++++++++++++++++ ...e937-cfb5-4679-989a-c3fea892568f.blade.php | 59 ++++++++------ 3 files changed, 135 insertions(+), 29 deletions(-) diff --git a/app/Helpers/TgicsHelper.php b/app/Helpers/TgicsHelper.php index 78fb0be0..c48105f4 100644 --- a/app/Helpers/TgicsHelper.php +++ b/app/Helpers/TgicsHelper.php @@ -95,6 +95,22 @@ class TgicsHelper return strtolower(trim((string) $value)) === 'yes'; } + /** + * Read validation flag from a contact object (supports attribute_ prefix). + */ + public static function contactHasWhatsappValidated($item): bool + { + if (!$item) { + return false; + } + $direct = $item->tgics_whatsapp_validated ?? null; + if (self::isWhatsappValidatedFlag($direct)) { + return true; + } + $prefixed = $item->attribute_tgics_whatsapp_validated ?? null; + return self::isWhatsappValidatedFlag($prefixed); + } + /** * Map contact_id => whether WhatsApp is validated for TGICS. * @@ -122,11 +138,16 @@ class TgicsHelper try { $resp = LambdaRequest::getrequest('contact', 'contact/get_one', ['id' => $id], $accessToken); $item = $resp->data->item ?? null; - if ($item && self::isWhatsappValidatedFlag($item->tgics_whatsapp_validated ?? '')) { - $status[$id] = true; - } + $validated = self::contactHasWhatsappValidated($item); + $status[$id] = $validated; + Log::info('[TGICS_WA_STATUS] contact lookup', [ + 'contact_id' => $id, + 'validated' => $validated, + 'flag' => $item->tgics_whatsapp_validated ?? ($item->attribute_tgics_whatsapp_validated ?? null), + 'api_status' => $resp->status ?? null, + ]); } catch (\Throwable $e) { - Log::warning('TGICS WhatsApp validation lookup failed for '.$id.': '.$e->getMessage()); + Log::warning('[TGICS_WA_STATUS] lookup failed for '.$id.': '.$e->getMessage()); } } diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index e048d53a..d5269226 100644 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -1705,6 +1705,43 @@ class FormController extends Controller } } + // Team3 doctor tagging (single submit): mark attribute = Yes on selected doctor(s) + $team3DrTagAttributes = [ + '1793772514-e8e67206-8dba-471e-b08f-deece5d36d11' => 'levoswitch_drs', + '1793767249-069bf040-1469-4117-b364-e4851e1f4bdf' => 'toba_titans_drs', + ]; + if (isset($team3DrTagAttributes[$formdata->form_id])) { + $tagAttribute = $team3DrTagAttributes[$formdata->form_id]; + $rawContactIds = $post['contact_id'] ?? []; + if (!is_array($rawContactIds)) { + $rawContactIds = [$rawContactIds]; + } + $contactIds = []; + foreach ($rawContactIds as $contactId) { + $contactId = trim((string) $contactId); + if ($contactId !== '' && strcasecmp($contactId, 'others') !== 0) { + $contactIds[] = $contactId; + } + } + $contactIds = array_values(array_unique($contactIds)); + if ($contactIds !== [] && !empty($formdata->partition)) { + list($application, $domain) = explode('-', $formdata->partition); + $token = DB::table('users')->select('access_token')->where('domain', $domain)->where('permissions', 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get(); + $userId = trim((string) ($post['user_id'] ?? ($formdata->user_id ?? ''))); + if ($token->isNotEmpty() && $userId !== '') { + foreach ($contactIds as $contactId) { + LambdaRequest::postrequest('contact', 'contact/update', [ + 'domain' => $domain, + 'application' => $application, + 'user_id' => $userId, + 'id' => $contactId, + $tagAttribute => 'Yes', + ], $token[0]->access_token); + } + } + } + } + if($formdata->form_id == '1757055046-ba0eff4e-0d4a-4e90-b190-c59f12ef6edd') { // if(isset($post['cresar_bs_launched']) && $post['cresar_bs_launched'] == 'Yes' ) { list($application, $domain) = explode("-", $formdata->partition); @@ -8104,6 +8141,40 @@ class FormController extends Controller ]); } + // Team3 doctor tagging: mark attribute = Yes on each selected doctor + $team3DrTagAttributes = [ + '1793772514-e8e67206-8dba-471e-b08f-deece5d36d11' => 'levoswitch_drs', + '1793767249-069bf040-1469-4117-b364-e4851e1f4bdf' => 'toba_titans_drs', + ]; + if (isset($team3DrTagAttributes[$formdata->form_id])) { + $tagAttribute = $team3DrTagAttributes[$formdata->form_id]; + $contactIds = []; + if (!empty($post['contact_id']) && is_array($post['contact_id'])) { + foreach ($post['contact_id'] as $contactId) { + $contactId = trim((string) $contactId); + if ($contactId !== '' && strcasecmp($contactId, 'others') !== 0) { + $contactIds[] = $contactId; + } + } + } + $contactIds = array_values(array_unique($contactIds)); + if ($contactIds !== [] && !empty($formdata->partition)) { + list($application, $domain) = explode('-', $formdata->partition); + $token = DB::table('users')->select('access_token')->where('domain', $domain)->where('permissions', 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get(); + $userId = trim((string) ($post['user_id'] ?? ($formdata->user_id ?? ''))); + if ($token->isNotEmpty() && $userId !== '') { + foreach ($contactIds as $contactId) { + LambdaRequest::postrequest('contact', 'contact/update', [ + 'domain' => $domain, + 'application' => $application, + 'user_id' => $userId, + 'id' => $contactId, + $tagAttribute => 'Yes', + ], $token[0]->access_token); + } + } + } + } if(isset($formdata) && !empty($formdata) && $formdata->user_id != '') { $post = $this->applyPobAmounts($post); @@ -13550,6 +13621,11 @@ class FormController extends Controller } $validated = \App\Helpers\TgicsHelper::isContactWhatsappValidated($contactId, $domain); + \Log::info('[TGICS_WA_STATUS] poll', [ + 'contact_id' => $contactId, + 'domain' => $domain, + 'validated' => $validated, + ]); return response()->json([ 'status' => 'success', diff --git a/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php b/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php index e549a444..5edac330 100644 --- a/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php +++ b/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php @@ -866,41 +866,50 @@ $('body').addClass('modal-open'); } + function checkTgicsWaStatus(contactId) { + return $.ajax({ + type: 'GET', + url: '/form/tgicswhatsappstatus', + data: { + contact_id: contactId, + partition: 'rapport-lifemankind' + } + }).then(function(res) { + if (res && res.status === 'success' && res.data && res.data.validated) { + stopTgicsWaPoll(); + $('#tgics-validate-wa-status').text('Validated!'); + Swal.fire({ + icon: 'success', + title: 'WhatsApp validated', + text: 'You can now send the survey link to this doctor.', + timer: 1800, + showConfirmButton: false + }).then(function() { + window.location.reload(); + }); + return true; + } + return false; + }, function(err) { + console.warn('[TGICS_WA_STATUS] poll failed', err); + return false; + }); + } + function startTgicsWaPoll(contactId) { stopTgicsWaPoll(); tgicsWaPollStartedAt = Date.now(); $('#tgics-validate-wa-status').text('Waiting for validation…'); - + // Immediate check, then every 2s + checkTgicsWaStatus(contactId); tgicsWaPollTimer = setInterval(function() { if (Date.now() - tgicsWaPollStartedAt > 120000) { stopTgicsWaPoll(); $('#tgics-validate-wa-status').text('Still waiting. Close and try Validate again after the doctor sends the message.'); return; } - $.ajax({ - type: 'GET', - url: '/form/tgicswhatsappstatus', - data: { - contact_id: contactId, - partition: 'rapport-lifemankind' - }, - success: function(res) { - if (res && res.status === 'success' && res.data && res.data.validated) { - stopTgicsWaPoll(); - $('#tgics-validate-wa-status').text('Validated!'); - Swal.fire({ - icon: 'success', - title: 'WhatsApp validated', - text: 'You can now send the survey link to this doctor.', - timer: 1800, - showConfirmButton: false - }).then(function() { - window.location.reload(); - }); - } - } - }); - }, 3000); + checkTgicsWaStatus(contactId); + }, 2000); } $(document).on('click', '.tgics-validate-wa-btn', function(e) {