Leave a comment at the end of this page or email contact@krishagni.com
Sample Code To Reserve and Unreserve Specimens
Introduction
This document provides instructions for using two Python scripts that interact with the OpenSpecimen API to reserve and unreserve specimens. These scripts accept a CSV input file and perform the necessary actions using OpenSpecimen’s API endpoints.
The two scripts included are:
reserveSpecimens.py: Reserves the specimens based on the information in the CSV file.
unreserveSpecimens.py: Unreserves the specimens based on the information in the CSV file.
Prerequisites
Before running the scripts, ensure that you have the following:
Python 3.x installed on your system.
The required Python libraries (e.g.,
requests
) installed.Access to the OpenSpecimen API with admin credentials.
A valid CSV input file with the distribution protocol and specimen ID to be reserved or unreserved.
Parameters
The scripts accept four parameters:
OpenSpecimen API URL: The URL where your OpenSpecimen instance is hosted.
Username: The username for logging into OpenSpecimen.
Password: The password for logging into OpenSpecimen.
CSV File: The CSV file containing the distribution protocol and specimen ID information.
Example CSV Format:"Distribution Protocol","Specimen Identifier" "DP1",13627 "DP1",5273 "DP2",738 "DP2",17283
Reserve Specimens Script
This script reserves specimens based on the distribution protocol and specimen ID provided in the CSV input file.
Script |
|
How to run? | python3 reserveSpecimens.py ‘<SERVER_URL>' '<USER_NAME>' '<PASSWORD>' '<CSV_FILE>' |
Unreserve Specimens Script
Script |
|
How to run? | python3 unreserveSpecimens.py ‘<SERVER_URL>' '<USER_NAME>' '<PASSWORD>' '<CSV_FILE>' |
To generate the CSV file you can use a OpenSpecimen Query module.
Steps to create a parametrized query to get distribution protocol short title and specimen identifier are:
A. Login to OpenSpeicmen → Navigate To → Query → Create
B. Select Specimen → Label → ALL as shown in the below image.
C. Click on View Records → Actions → Columns → Select Only Needed Columns → Done
Output:
Leave a comment at the end of this page or email contact@krishagni.com