Prefer using email? Say hi at hello@moveshelf.com
## README: this example shows how we can retrieve a subject from Moveshelf
# using the Moveshelf API.
# For a given project (my_project), retrieve a subject based on either the given MRN (my_subject_mrn)
# or the subject name (my_subject_name)
## 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", set to None if you want to use the name
my_subject_name = "<subjectName>" # subject name, set to None if you want to use the MRN
## 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"]
## Find the subject based on MRN or name
subject_found = False
if my_subject_mrn is not None:
subject = api.getProjectSubjectByEhrId(my_subject_mrn, my_project_id)
if subject is not None:
subject_found = True
if not subject_found and my_subject_name is not None:
subjects = api.getProjectSubjects(my_project_id)
for subject in subjects:
if my_subject_name == subject['name']:
subject_found = True
break
if my_subject_mrn is None and my_subject_name is None:
print("We need either subject mrn or name to be defined to be able to search for the subject.")
## Print message
if subject_found:
subject_details = api.getSubjectDetails(subject["id"])
subject_metadata = json.loads(subject_details.get("metadata", "{}"))
print(
f"Found subject with name: {subject_details['name']},\n"
f"id: {subject_details['id']}, \n"
f"and MRN: {subject_metadata.get('ehr-id', None)}"
)
else:
print(
f"Couldn't find subject with MRN: {my_subject_mrn},\n"
f"in project: {my_project}"
)