fix: auto-populate prescription content and lab content from pre-selected defaults

This commit is contained in:
SajjadMahmoody
2026-04-18 13:45:07 +03:30
parent bbb727cffe
commit 4abd856bf9
7 changed files with 147 additions and 22 deletions
@@ -182,6 +182,16 @@ public static function form(Schema $schema): Schema
)
->columns(3)
->live()
->afterStateHydrated(function (array $state, callable $set, callable $get) {
if (empty($state) || ! empty($get('lab_content'))) {
return;
}
$order = array_map('intval', $state);
$set('lab_test_order', $order);
$tests = LabTest::whereIn('id', $order)->get()->keyBy('id');
$html = '<ul>' . collect($order)->map(fn ($id) => isset($tests[$id]) ? '<li>' . $tests[$id]->name . '</li>' : '')->filter()->implode('') . '</ul>';
$set('lab_content', $html);
})
->afterStateUpdated(function (array $state, callable $set, callable $get) {
$currentOrder = array_map('intval', (array) ($get('lab_test_order') ?: []));
$state = array_map('intval', $state);