Prefer using email? Say hi at hello@moveshelf.com
## README: this example shows how we can import subject metadata to an existing
# subject on Moveshelf using the Moveshelf Python API.
# This code assumes you have implemented the 'Create 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
# For that subject, update subject metadata (my_subject_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
# Manually define the subject metadata dictionary you would like to import
my_subject_metadata = {
"subject-first-name": "<subjectFirstName>",
"subject-middle-name": "<subjectMiddleName>",
"subject-last-name": "<subjectLastName>",
"ehr-id": my_subject_mrn,
"interventions": [ # List of interventions
{
"id": 0, # <idInterv1>
"date": "<dateInterv1>", # "YYYY-MM-DD" format
"site": "<siteInterv1>",
"surgeon": "<surgeonInterv1>",
"procedures": [
{
"side": "<sideProc1Interv1>",
"location": "<locationProc1Interv1>",
"procedure": "<procedureProc1Interv1>",
"location-modifier": "<locationModProc1Interv1>",
"procedure-modifier": "<procedureModProc1Interv1>"
},
{
"side": "<sideProc2Interv1>",
# ... You can add multiple procedures
}
],
"surgery-dictation": "<surgeryDictationInterv1>"
},
# ... Additional interventions can be added here, each represented as a dictionary
# Increment the "id" for each new intervention (e.g., 1, 2, 3,...)
# Ensure each intervention contains a complete set of fields
]
# ... Add additional fields you would like to import
}
## Add here the code to retrieve the project and find an existing subject and its "subject_details"
# ... subject_found = True
# Import subject metadata
subject_updated = api.updateSubjectMetadataInfo(
subject["id"], json.dumps(my_subject_metadata)
)
# 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 interventionMetadata list from metadata JSON
my_subject_metadata["interventions"] = local_metadata.get("interventionMetadata", [])
# Fetch subject details using the subject ID
subject_details = api.getSubjectDetails(subject["id"])
subject_metadata = json.loads(subject_details.get("metadata", "{}"))
# Print the subject details
print(f"Created subject with name: {subject_details['name']},\n"
f"id: {subject_details['id']}, \n"
f"and metadata: {subject_metadata}")