Adding Users in Bulk

When Clarity LIMS is replacing an existing LIMS, or if the LDAP integration is not being utilized, a list of current LIMS users and collaborators often already exists in a file.

In this scenario, it is useful to use this file to create users in Clarity LIMS. This topic provides an example script and outlines a strategy for the bulk import of users from a simple CSV file.

Solution

The attached script parses a CSV file containing user information. Based on the columns of data present in the file, the script then creates users and their associated labs in Clarity LIMS.

Parameters

Since this operation is independent of workflow and sample processing, the parameters used to invoke the script differ from those typically used:

-h

The URI of the server to which you want to upload the users (Required)

-u

The username of a user with administrative privileges (Required)

-p

The password of the user (Required)

-f

The path to the CSV file containing the user-related data (Required)

An example of the full syntax to invoke the script is as follows:

/usr/bin/python /opt/gls/clarity/customextensions/userImport.py -h http://192.168.8.10:8080 -u admin -p securepassword -f ./user_list.csv

File format

The format of the file is very flexible. The order of the columns is not relevant.

If the names of your columns do not match the column names in the example file, modify the script so that the column names match yours.

uNameIndex = COLS[ "User"]
fnameIndex = COLS[ "First Name" ]
lNameIndex = COLS[ "Last Name" ]
eMailIndex = COLS[ "E-mail" ]
labIndex = COLS[ "Institution" ]

Attached to this topic, you'll find a CSV file containing test data that illustrates the format further. The structure of this file is shown below.

Notice that the first two rows do not contain data of interest, and so the script ignores them. This is controlled by line 38 of the script, which specifies the location of the header row:

headerRow = 3 

About the Code

The main method of interest is importData(). After parsing the file into data structures (COLS and DATA), the data is processed one line at a time using the following pseudocode:

does a user with this username already exist?

if NO:

    does the lab exist?

    if NO:

        createLab

    createUser

To reduce the number of queries the script makes back to the server, each time a new lab is created it is added to the cache of existing labs that is stored in the LABS dictionary.

Finally, if you set the DEBUG variable to true, the script will stop processing the file after the first successful creation of a user. This is useful as it allows you to test your script using just one line of the CSV file at a time.

Assumptions and Notes

  • Both of the attached *.py script files are placed on the Clarity LIMS server, in the /opt/gls/clarity/customextensions folder.

  • The users will be created with the same hard-coded password (abcd1234). It is possible to have the script create a unique password for each user. If this is required, consider having the script e-mail the user with a 'welcome' e-mail outlining their username and password.

  • The users will be created with permissions to access the Collaborations Interface only. This can be modified as required.

  • The contents of the 'Institution' column will be used to associate the user with a 'Lab', if a value for this column is provided.

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

Attachments

user_List_Test.csv:

userImport.py:

Last updated