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']
parentFolder = os.path.dirname(os.path.dirname(__file__))
sys.path.append(parentFolder)
from api.api import MoveshelfApiCustomized
## Setup the API
# Load config
with open(os.path.join(parentFolder, "mvshlf-config.spec.json"), "r") as configFile:
data = json.load(configFile)
# And overwrite if available
personalConfig = os.path.join(parentFolder, "mvshlf-config.json")
if os.path.isfile(personalConfig):
with open(personalConfig, "r") as configFile:
data.update(json.load(configFile))
# Use custom API
api = MoveshelfApiCustomized(api_key_file=os.path.join(parentFolder, data["apiKeyFileName"]), api_url=data["apiUrl"])
# ... rest of the code to access a project on Moveshelf via API ..
# 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']}")