-
- @foreach($questions as $question)
- @if( in_array($question->code,
- ["record_date","select_rxber_type"] ) )
- @continue;
+ @if($row && !empty($row->id))
+
@endif
+ @foreach($questions as $question)
+ @if(in_array($question->code, ["record_date","select_rxber_type"]))
+ @continue
+ @endif
+ @php
+ $fieldName = $question->code.'['.$index.']';
+ if ($question->code === 'contact_id') {
+ $fieldId = $isFirstDoctor ? 'field-contact_id' : 'field-contact_id-'.$index;
+ } elseif ($question->type === 'dropdown' && $isFirstDoctor) {
+ $fieldId = 'execution-'.$question->code;
+ } else {
+ $fieldId = $isFirstDoctor ? 'field-'.$question->code : 'field-'.$question->code.'-'.$index;
+ }
+ $textValue = '';
+ if ($row && isset($row->formdata) && isset($row->formdata->{$question->code})) {
+ $textValue = $row->formdata->{$question->code};
+ if (is_array($textValue)) {
+ $textValue = reset($textValue);
+ }
+ if (is_object($textValue)) {
+ $textValue = '';
+ }
+ } elseif (!$row && isset($question->value)) {
+ $textValue = $question->value;
+ }
+ if ($question->code === 'contact_id') {
+ $textValue = $row ? $doctorContactId($row) : (isset($question->value) ? $question->value : '');
+ }
+ $checkedValues = [];
+ if ($row && isset($row->formdata) && isset($row->formdata->{$question->code})) {
+ $rawCheck = $row->formdata->{$question->code};
+ $checkedValues = is_array($rawCheck) ? $rawCheck : [$rawCheck];
+ } elseif (!$row && isset($question->value) && $question->value !== '') {
+ $checkedValues = is_array($question->value) ? $question->value : [$question->value];
+ }
+ @endphp
@endforeach