fix: auto-populate prescription content and lab content from pre-selected defaults
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user