Adding Downstream Samples to Additional Workflows

When processing samples, there can be circumstances in which you must add downstream samples to additional workflows. This sample addition is not easy to achieve using the Server Name interfaces, but is easy to do via the API.

Solution

This example provides a Python script that can be used to add samples to an additional workflow step. The example also includes information on the key API interactions involved.

  • It is the outputs, not the inputs, of the process that are added to the workflow step. (If you would like to add the inputs, changing this step is simple.)

  • This example is an add function, not a move. If you would like to remove the samples from the current workflow, you can do arrange to do so by building an <assign> element.

  • The process is configured to produce analyte outputs, and not result files.

Parameters

The script accepts the following parameters:

About the Code

The step URI (-s) parameter is used to report a meaningful message and status back to the user. These reports depend upon the outcome of the script.

Initially, the parameters are gathered and the helper object defined in the glsapiutil.py has been instantiated and initialized. Its methods can be called to take care of the RESTful GET/PUT/POST functionality. The script calls the following functions:

Once the parameters have been gathered, and the helper object defined in the glsapiutil.py has been instantiated and initialized, its methods can be called to take care of the RESTful GET/PUT/POST functionality, leaving the script to call the following functions:

  • getStageURI()

  • routeAnalytes().

getStageURI() function

The getStageURI() function converts the workflowname and stagename parameters into a URI that is used as the assign element, for example:

<assign stage-uri="http://localhost:8090/api/v2/configuration/workflows/7/stages/4">  

routeAnalytes() function

The routeAnalytes() function gathers the outputs of the process, and harvests their URIs to populate in the <artifact> elements. This function also uses the reporting mechanism based upon the step URI parameter.

API resource

The crucial resource in this example is the route/artifacts resource. This API endpoint can only be POSTed to, and accepts XML of the following form:

<rt:routing xmlns:rt="http://genologics.com/ri/routing">
  <assign stage-uri="http://localhost:8090/api/v2/configuration/workflows/7/stages/4">
    <artifact uri="http://localhost:8090/api/v2/artifacts/5"/>
    <artifact uri="http://localhost:8090/api/v2/artifacts/6"/>
  </assign>
  <assign workflow-uri="http://localhost:8090/api/v2/configuration/workflows/7">
    <artifact uri="http://localhost:8090/api/v2/artifacts/8"/>
    <artifact uri="http://localhost:8090/api/v2/artifacts/9"/>
  </assign>
  <unassign workflow-uri="http://localhost:8090/api/v2/configuration/workflows/10">
    <artifact uri="http://localhost:8090/api/v2/artifacts/11"/>
    <artifact uri="http://localhost:8090/api/v2/artifacts/12"/>
  </unassign>
</rt:routing>

For more information, refer to the route/artifacts REST API documentation. Also useful are the configuration/workflow resources, both single and list.

Assumptions and Notes

  • The attached file is placed on the Clarity LIMS server, in the /opt/gls/clarity/customextensions folder.

  • The Python API Library (glsapiutil.py) is placed on the Clarity LIMS server, in the /opt/gls/clarity/customextensions folder. You can download the latest glsapiutil library from our GitHub page.

  • You must update the HOSTNAME global variable such that it points to your Clarity LIMS server.

  • The example code is provided for illustrative purposes only. It does not contain sufficient exception handling for use 'as is' in a production environment.

Attachments

addToStep.py:

Last updated