Question: in this sub: sub _SortProcedureStageOrders { my ($args) = @_; AssertSimpleFields($args, [qw( ORDERS )]); my $orders = $args->{ORDERS}; my %stage_groups; # Define the desired order
in this sub: sub _SortProcedureStageOrders { my ($args) = @_; AssertSimpleFields($args, [qw( ORDERS )]); my $orders = $args->{ORDERS}; my %stage_groups; # Define the desired order of stages my %stage_order = ( Preop => 1, Intraop => 2, Recovery => 3, Postop => 4, ); # Group orders by procedure stage foreach my $order (@$orders) { my $stage = $order->{ascMarOrderDetails}->{procedureStageName}; push @{$stage_groups{$stage}}, $order; } my @sorted_orders; # Store the sorted stages in a variable my @sorted_stages = sort { $stage_order{$a} <=> $stage_order{$b} } keys %stage_groups; # Sort each stage group foreach my $stage (@sorted_stages) { my @stage_orders = @{$stage_groups{$stage}}; # Sort within the stage: non-PRN first, then PRN @stage_orders = sort { (($a->{isPrn} ne '' ? $a->{isPrn} : 0) <=> ($b->{isPrn} ne '' ? $b->{isPrn} : 0)) || _SortOrderTiebreak({ FIRSTORDER => $a, SECONDORDER => $b }) } @stage_orders; # Add sorted stage orders to the final list push @sorted_orders, @stage_orders; } return \@sorted_orders; } rather than creatign a stage_order and sorting it. Can we directly call it in foreach my $stage (@sorted_stages) and state to order first with Preop, Intraop, Resovery and Postop
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
