25.3.6.5 Continuing a Waiting Lifecycle Workflow
Continue the waiting workflow activity and pass the event type into a workflow variable.
When the PROCESS_EVENT procedure in the
FRC_PROCEDURE_LIFECYCLE package executes, it calls
NOTIFY_DATA_CHANGED shown below. This calls a local helper function
WORKFLOW_ID_FOR_WAITING_ACTIVITY to look up the
procedure_lifecycle workflow instance ID for the current medical
procedure row.
In the process, it ensures the workflow is active and has an activity with
Static ID
status_or_date_changed that is waiting to continue. If such a workflow
instance is found, it passes its ID to CONTINUE_ACTIVITY in the
APEX_WORKFLOW package to signal the waiting activity to
continue.
It passes a map of name/value pairs back to the activity including the key V_WHAT_CHANGED whose value is the event type passed in. Any workflow variable whose name matches a map key value is automatically assigned the corresponding value in the process. Consequently, the V_WHAT_CHANGED workflow variable then contains the event type and the workflow continues to the next activity.
-- internal in package frc_procedure_lifecycle
------------------------------------------------------------------
-- Notify an instance of the procedure_lifecycle workflow associated
-- with the supplied patient procedure id that
------------------------------------------------------------------
function notify_data_changed(
p_procedure_id in number,
p_event_type in varchar2)
return boolean
is
l_workflow_id number := workflow_id_for_waiting_activity(
'procedure_lifecycle',
'status_or_date_changed',
p_procedure_id);
begin
if l_workflow_id is not null then
apex_workflow.continue_activity(
p_instance_id => l_workflow_id,
p_static_id => 'status_or_date_changed',
p_activity_params => apex_global_application.vc_map(
'V_WHAT_CHANGED' => p_event_type));
return true;
end if;
return false;
end notify_data_changed;The WORKFLOW_ID_FOR_WAITING_ACTIVITY helper function ensures the procedure lifecycle workflow for the Details Primary Key value passed in is active and that the desired activity is waiting. If both of these conditions hold, then it returns the ID of that workflow instance. Otherwise, it returns null.
-- internal in package frc_procedure_lifecycle
------------------------------------------------------------------
-- Return the active workflow id of static def id type passed in
-- associated with provided PK and having a waiting activity with
-- supplied static id that can be continued. Otherwise, null
------------------------------------------------------------------
function workflow_id_for_waiting_activity(
p_workflow_static_id in varchar2,
p_waiting_activity_static_id in varchar2,
p_details_pk in varchar2)
return number
is
l_ret number;
begin
-- Only return the workflow id if the workflow is in ACTIVE
-- state and the indicated continue activity is in WAITING state
for wf in ( select workflow_id
from apex_workflow_activities ac
join apex_workflows wf using (workflow_id)
where wf.detail_pk = p_details_pk
and wf.workflow_def_static_id = p_workflow_static_id
and ac.static_id = p_waiting_activity_static_id
and ac.state = 'WAITING'
and wf.state_code = 'ACTIVE')
loop
l_ret := wf.workflow_id;
end loop;
if l_ret is null then
apex_debug.warn('workflow_id_for_waiting_activity: No active workflow (%s)'
|' with activity (%s) waiting for pk (%s)',
p_workflow_static_id,
p_waiting_activity_static_id,
p_workflow_static_id);
end if;
return l_ret;
end workflow_id_for_waiting_activity;Parent topic: Notifying Workflow of Data Changes