It is sometimes necessary to assign a sample to a new workflow from within another workflow.
You can do this in the BaseSpace Clarity LIMS Operations Interface, by manually adding the sample to the desired workflow. However, it is also possible to perform this action through the API.
This example shows how to use the API to automate the addition of samples to a specified workflow, based on a UDF value.
The script can be run off any protocol step whose underlying process is configured with Analyte inputs and a single per-input ResultFile output.
The process may have any number of per-all-input ResultFile outputs, as they will be ignored by the script.
A Result File UDF, named Validate, will control which samples will be added to the specified workflow.
The script accepts the following parameters:
-s
The URI of the step that launches the script (Required)
The {stepURI:v2:http} token (in the form http://<YourIP>/api/v2/steps/<ProtocolStepLimsid>)
-u
The username of the current user (Required)
The {username} token
-p
The password of the current user (Required)
The {password} token
-w
The name of the destination workflow (Required)
The {workflow} token
Before the example script can be used, first create the ResultFile's Validate UDF in the Operations Interface. This is a single-line text UDF with preset values of 'Yes' and 'No'.
Also in the Operations Interface, create a new process type named Cookbook Workflow Addition.
This process type must:
Have Analyte inputs.
Have a single per-input ResultFile output.
Apply the Validate UDF on its ResultFile outputs.
Once the process type is created, in the Clarity LIMS Web Interface, create a protocol named Cookbook Workflow Addition Protocol.
This protocol should have one the protocol step - Cookbook Workflow Addition.
Configure the EPP script to automatically initiate at the end of the Cookbook Workflow Addition step:
To finish configuration, create two workflows:
Destination Workflow: THis workflow should contain the DNA Initial QC protocol only.
Sending Workflow: This workflow should contain the new Cookbook Workflow Addition Protocol.
Once the script has processed the input parameters and ensured that all the required information is available, we can start processing the samples to determine if they should be assigned to the new workflow.
To begin, we retrieve the process from the API. This gives us access to the input-output maps of the process. These will be used to determine which ResultFiles we will examine.
Next, we retrieve the protocol step action list. This contains a list of the input analytes' URIs and their next steps.
We then search this list for and collect all analyte URIs whose next action has been set to Mark as protocol complete.
Next, we gather the per-input ResultFile input-output maps. We can collect the ResultFile URIs of those related to the analytes who have been marked as complete. NOTE: It is important that we strip any extra state information from the URIs. The URIs found in the next action list do not contain any state information and, when compared against a non-stripped URI, will return 'false'.
Once we have the ResultFile URIs, we can retrieve them with batchGET. It is important that the list contains unique URIs, as the batchGET will fail otherwise.
After we have retrieved the ResultFiles, we can iterate through the list, adding the parent sample's URI to our list of sample URIs if the ResultFile's Validate UDF is set to Yes. We also increment a counter which will allow us to report to the user how many samples were assigned to the new workflow.
Since we don't assign samples themselves to workflows, we first need to retrieve the samples' derived artifacts. We can do this by iterating through each sample URI, retrieving it, and adding its artifact's URI to a list.
Before we can add the artifacts to the workflow, we need to determine the destination workflow's URI. By retrieving a list of all the workflows in the system, we can find the one that matches our input workflow name.
Assigning artifacts to workflows requires the posting of a routing command to the routing endpoint.
We first generate the required XML by using a Streaming Markup Builder.
We then dynamically build our XML by looping inside of the markup declaration. // Create a new routing assignment using the Markup Builder
To create our routing command, we pass the workflow URI and the artifact URIs that we wish to assign to the workflow to a method containing the above code. This will generate the required node.
We then perform an httpPOST to the routing endpoint to perform the action.
Finally, we define our success message to the user. This will allow us to inform the user of the results of the script.
Assuming samples have been placed in the Switching Workflow, the user proceeds as normal through the protocol step.
In the Record Details screen, the user enters Validate values in the ResultFile UDFs.
A message displays, alerting the user of the execution of a custom script.
The attached file is placed on the Clarity LIMS server, in the /opt/gls/clarity/customextensions folder.
GLSRestApiUtils.groovy is placed in the Groovy lib folder.
The required configuration has been set up, as described in Configuration.
The example code is provided for illustrative purposes only. It does not contain sufficient exception handling for use 'as is' in a production environment.
SwitchingWorkflows.groovy:
The user then proceeds to the Assign Next Steps screen, provides a variety of Next Steps, and completes the protocol step.
When the script completes, a success message displays and the samples are added to the specified workflow.