Get in touch

Get in touch

Prefer using email? Say hi at hello@moveshelf.com

This section explains how to retrieve a session with a specific date for a subject with a specified MRN on Moveshelf using the Moveshelf API.
Prerequisites
Before implementing this example, ensure that your processing script includes all necessary setup steps. In particular, you should have:
Implementation
To retrieve a session with a specific date from a subject, add the following lines of code to your processing script:
## README: this example shows how we can retrieve sessions from Moveshelf 
# using the Moveshelf API.
# This code assumes you have implemented the 'Retrieve subject' example, and
# that you have found the subject with a given EHR-id/MRN (my_subject_mrn)
# or name (my_subject_name) within a given project (my_project), and that you 
# have access to the subject ID. 
# Then, for that subject, retrieve the specified session (my_session).


## General configuration. Set values before running the script
my_project = "<organizationName/projectName>"  # e.g. support/demoProject
my_subject_mrn = "<subjectMRN>"  # subject MRN, e.g. "1234567" or None
my_subject_name = "<subjectName>"  # subject name, e.g. Subject1 or None
my_session = "<sessionDate>" # "YYYY-MM-DD" format

## Add here the code to retrieve the project and find an existing subject and its "subject_details"
# ... subject_found = True

## Get sessions
sessions = subject_details.get("sessions", [])

# Loop over sessions
session_found = False
for session in sessions:
    try:
        session_name = session["projectPath"].split("/")[2]
    except:
        session_name = ""
    if session_name == my_session:
        session_found = True
        session_id = session["id"]
        print(
            f"Found session with projectPath: {session['projectPath']},\n"
            f"and id: {session_id}"
        )
        break

if not session_found:
    print(
        f"Couldn't find session: {my_session},\n"
        f"for subject with MRN: {my_subject_mrn}"
    )