Prefer using email? Say hi at hello@moveshelf.com
from moveshelf_api.api import MoveshelfApi
# Custom Moveshelf API class that extends the existing API
class MoveshelfApiCustomized(MoveshelfApi):
def getProjectSubjectsCustom(self, project_id):
data = self._dispatch_graphql(
'''
query getProjectPatients($projectId: ID!) {
node(id: $projectId) {
... on Project {
id,
name,
description,
canEdit,
patients {
id
name
metadata
sessions {
id
date
metadata
}
}
}
}
}
''',
projectId = project_id
)
return data['node']['patients']
parent_folder = os.path.dirname(os.path.dirname(__file__))
sys.path.append(parent_folder)
from api.api import MoveshelfApiCustomized
## Setup the API
# Load config
personal_config = os.path.join(parent_folder, "mvshlf-config.json")
if not os.path.isfile(personal_config):
raise FileNotFoundError(
f"Configuration file '{personal_config}' is missing.\n"
"Ensure the file exists with the correct name and path."
)
with open(personal_config, "r") as config_file:
data = json.load(config_file)
# Use custom API
api = MoveshelfApiCustomized(
api_key_file=os.path.join(parent_folder, data["apiKeyFileName"]),
api_url=data["apiUrl"]
)
## General configuration. Set values before running the script
my_project = "<organizationName/projectName>" # e.g. support/demoProject
## Get available projects
projects = api.getUserProjects()
## Select the project
project_names = [project["name"] for project in projects if len(projects) > 0]
idx_my_project = project_names.index(my_project)
my_project_id = projects[idx_my_project]["id"]
# Custom query (defined in ../api/api.py) that extracts the metadata of all patients
# and the metadata of all their sessions within a given project
subjects = api.getProjectSubjectsCustom(my_project_id)
# Print the subject data
for subject in subjects:
print(f"Subject: {subject['name']} (ID: {subject['id']})")
print(f"Metadata: {subject['metadata']}")
print("Sessions:")
for session in subject['sessions']:
print(f" - Session {session['id']} on {session['date']} with metadata: {session['metadata']}")