Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Update Healthcode to MD5 hash table for JourneyPro, Presence, ElevateMS
import bridgeclient
import hashlib
import pandas as pd
import synapseclient as sc
import argparse
SYNAPSE_TABLES = {
'journey-pro': 'syn11439373',
'elevate-ms': 'syn11439398',
'lilly-presence': 'syn11445782'}
def read_args():
parser = argparse.ArgumentParser(description="Export MD5 hashes of "
"participant's email addresses coupled with their healthcode identifier.")
parser.add_argument("study")
parser.add_argument("email")
parser.add_argument("password")
args = parser.parse_args()
return args
def getmd5(s):
m = hashlib.md5()
m.update(s.encode('utf-8'))
return m.hexdigest().upper()
def main():
args = read_args()
syn = sc.login()
bc = bridgeclient.bridgeConnector(email=args.email,
password=args.password, study=args.study)
bridge_data = bc.getParticipants()
synapse_data = syn.tableQuery("select id from {}".format(
SYNAPSE_TABLES[args.study])).asDataFrame()
new_rows = [not i in synapse_data.id.values for i in bridge_data.id.values]
if any(new_rows):
bridge_metadata = map(lambda id: bc.getParticipantMetaData(id),
bridge_data.id.values)
bridge_metadata = pd.DataFrame(list(bridge_metadata))
metadata_rel = bridge_metadata[['id', 'healthCode']]
bridge_merged = bridge_data.merge(metadata_rel, on='id')
bridge_merged = bridge_merged.loc[new_rows,:]
hashes = list(map(getmd5, bridge_merged.email.values))
bridge_merged['externalId'] = hashes
table = sc.Table(SYNAPSE_TABLES[args.study],
bridge_data[['externalId', 'healthCode']].values)
syn.store(table)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment