@@ -927,6 +927,54 @@ public void markProcedureOrderComplete(List<String> orderids)
927927 }
928928 }
929929
930+ public void updateProcedureOrdersToCompleted (List <String > ids )
931+ {
932+ if (ids == null || ids .size () < 1 ) // Native array doesn't support isEmpty
933+ {
934+ _log .warn ("No IDs provided to updateProcedureOrdersToCompleted" );
935+ return ;
936+ }
937+
938+ TableInfo ti = getTableInfo ("study" , "prc_order" );
939+
940+ // Get the QC state IDs for "Request: Approved" and "Completed"
941+ Integer approvedQcStateId = EHRService .get ().getQCStates (_container ).get (EHRService .QCSTATES .RequestApproved .getLabel ()).getRowId ();
942+ Integer completedQcStateId = EHRService .get ().getQCStates (_container ).get (EHRService .QCSTATES .Completed .getLabel ()).getRowId ();
943+
944+ // Query for rows matching the IDs and having "Request: Approved" status
945+ SimpleFilter filter = new SimpleFilter (FieldKey .fromString ("Id" ), ids , CompareType .IN );
946+ filter .addCondition (FieldKey .fromString ("qcstate" ), approvedQcStateId , CompareType .EQUAL );
947+
948+ TableSelector ts = new TableSelector (ti , PageFlowUtil .set ("objectid" ), filter , null );
949+ Map <String , Object >[] results = ts .getMapArray ();
950+
951+ if (results .length == 0 )
952+ {
953+ _log .info ("No prc_order rows found with 'Request: Approved' status for the provided IDs" );
954+ return ;
955+ }
956+
957+ // Build the update rows
958+ List <Map <String , Object >> rows = new ArrayList <>();
959+ for (Map <String , Object > result : results )
960+ {
961+ Map <String , Object > row = new HashMap <>();
962+ row .put ("objectid" , result .get ("objectid" ));
963+ row .put ("qcstate" , completedQcStateId );
964+ rows .add (row );
965+ }
966+
967+ try
968+ {
969+ ti .getUpdateService ().updateRows (_user , _container , rows , null , null , getExtraContext ());
970+ _log .info ("Successfully updated " + rows .size () + " prc_order rows to 'Completed' status" );
971+ }
972+ catch (Exception e )
973+ {
974+ _log .error ("Error updating prc_order rows to completed" , e );
975+ }
976+ }
977+
930978 public void sendPregnancyOutcomeNotification (final String animalId , Map <String , Object > row ) throws Exception
931979 {
932980 //check whether Notification is enabled
0 commit comments