-
Notifications
You must be signed in to change notification settings - Fork 8
Study procedures
Thaliehln edited this page Jul 19, 2022
·
4 revisions
To be completed
- Run the code that allows to backup the ODK Central server through the ODK API on a daily basis
import requests
import os
import json
import cgi
import pandas as pd
from xml.etree import ElementTree
def get_session_token(central_url, central_email, central_password):
email_token_response = requests.post(
central_url + "/v1/sessions",
data = json.dumps({"email": central_email,
"password": central_password}),
headers = {"Content-Type": "application/json"},
)
if email_token_response.status_code == 200:
return email_token_response.json()["token"]
def backup(central_url, session_token, passphrase):
backup_response = requests.post(
central_url + "/v1/backup",
data = json.dumps({"passphrase": passphrase}),
headers = {"Authorization": "Bearer " + session_token,
"Content-Type": "application/json"},
stream = True
)
if backup_response.status_code == 200:
_, params = cgi.parse_header(backup_response.headers.get('Content-Disposition', ''))
filename = params["filename"].replace(":","-")
file = open(filename, "wb")
file.write(backup_response.content)
print("Backup successful")
-
Check that the table
patient.csv
does not contain any personally identifiable information:- first name
- last name
- middle name
- date of birth
To be completed