Skip to content

Instantly share code, notes, and snippets.

@tashrifbillah
Last active September 7, 2023 18:40
Show Gist options
  • Save tashrifbillah/0fe167e79b73c9ed895076fcd3277407 to your computer and use it in GitHub Desktop.
Save tashrifbillah/0fe167e79b73c9ed895076fcd3277407 to your computer and use it in GitHub Desktop.
Erase calcs, logics from REDCap dict to upload to a REDCap project
import pandas as pd
# this is API pulled from Yale REDCap
filename='pronet_dict_20230321.csv'
df=pd.read_csv(filename, dtype=str)
df1=df.copy()
# erase calcs, logics
# replace calc by text
for i,row in df.iterrows():
if row['Field Type']=='calc':
if row['Choices, Calculations, OR Slider Labels']:
df1.at[i,'Choices, Calculations, OR Slider Labels']=''
df1.at[i,'Field Type']='text'
if row['Branching Logic (Show field only if...)']:
df1.at[i,'Branching Logic (Show field only if...)']=''
# confirm calcs have been erased
for i,row in df1.iterrows():
if row['Field Type']=='calc':
calc=row['Choices, Calculations, OR Slider Labels']
if calc!='':
print(calc)
# confirm logics have been erased
for i,row in df1.iterrows():
calc=row['Branching Logic (Show field only if...)']
if calc!='':
print(calc)
# upload this to REDCap project
df1.to_csv(filename.replace('.csv','_calc_logic_erased.csv'), index=False)
# it does not need to be present locally
# only the output of modify_dict.py is enough
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment