Prefer using email? Say hi at hello@moveshelf.com
## README: this example shows how we can import session metadata to an existing
# session on Moveshelf using the Moveshelf Python API.
# This code assumes you have implemented the 'Create session' example, and
# that you have found the session (my_session) for a 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 session ID and session_name
# For that session, update session metadata (my_session_metadata)
## 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
my_session = "<sessionDate>" # "YYYY-MM-DD" format
# Manually define the session metadata dictionary you would like to import
my_session_metadata = {
"interview-fms5m": "1",
"vicon-leg-length": [
{
"value": "507",
"context": "left"
},
{
"value": "510",
"context": "right"
}
],
# ... Add additional fields you would like to import
}
## Add here the code to retrieve the project and find an existing subject
## and existing session
# loop over sessions until we find session_found = True
session_id = session["id"]
session = api.getSessionById(session_id) # get all required info for that session
updated_session = api.updateSessionMetadataInfo(
session_id,
session_name,
json.dumps({"metadata": my_session_metadata})
)
print(f"Updated session {session_name}: {updated_session}")
# Define the path to the local JSON file
local_metadata_json = os.path.join(parent_folder, "moveshelf_config_import.json")
# Load JSON file
with open(local_metadata_json, "r") as file:
local_metadata = json.load(file)
# Extract subjectMetadata dictionary from metadata JSON
my_subject_metadata = local_metadata.get("subjectMetadata", {})
my_subject_mrn = my_subject_metadata.get("ehr-id", "")
# Extract sessionMetadata dictionary from metadata JSON
my_session_metadata = local_metadata.get("sessionMetadata", {})
# Fetch session details using the session ID
updated_session_details = api.getSessionById(session_id)
updated_session_metadata = updated_session_details.get("metadata", None)
# Print updated session metadata
print(
f"Updated session with projectPath: {session['projectPath']},\n"
f"id: {session_id}.\n"
f"New metadata: {updated_session_metadata}"
)