Skip to content

Instantly share code, notes, and snippets.

@tashrifbillah
Last active July 13, 2022 21:21
Show Gist options
  • Save tashrifbillah/28f446eb388d2a34b055b9e737a12b97 to your computer and use it in GitHub Desktop.
Save tashrifbillah/28f446eb388d2a34b055b9e737a12b97 to your computer and use it in GitHub Desktop.
chrpsychs_scr_ac8 calc outside REDCap
import numpy as np
# initialize blank data
dict1={}
for i in range(1,16):
dict1[f'chrpsychs_scr_{i}a10']=''
dict1[f'chrpsychs_scr_{i}a10_on']=''
dict1[f'chrpsychs_scr_{i}a6_on']=''
# test data for chrpsychs_scr_ac8=1
dict1['chrpsychs_scr_1a10_on']=1
dict1[f'chrpsychs_scr_1a10_on']='2022-01-01'
dict1[f'chrpsychs_scr_1a6_on']='2022-07-01'
dict1['chrpsychs_scr_9a10_on']=1
dict1[f'chrpsychs_scr_9a10_on']='2020-07-01'
dict1[f'chrpsychs_scr_9a6_on']='2021-01-01'
# test data for chrpsychs_scr_ac8=0
dict1['chrpsychs_scr_1a10_on']=1
dict1[f'chrpsychs_scr_1a10_on']='2022-01-01'
dict1[f'chrpsychs_scr_1a6_on']='2022-07-01'
dict1['chrpsychs_scr_9a10_on']=0
dict1[f'chrpsychs_scr_9a10_on']=''
dict1[f'chrpsychs_scr_9a6_on']='2021-01-01'
dict1={'chrpsychs_scr_1a10': 1,
'chrpsychs_scr_1a10_on': '2022-01-01',
'chrpsychs_scr_1a6_on': '2022-07-01',
'chrpsychs_scr_2a10': 1,
'chrpsychs_scr_2a10_on': '',
'chrpsychs_scr_2a6_on': '',
'chrpsychs_scr_3a10': '',
'chrpsychs_scr_3a10_on': '',
'chrpsychs_scr_3a6_on': '',
'chrpsychs_scr_4a10': '',
'chrpsychs_scr_4a10_on': '',
'chrpsychs_scr_4a6_on': '',
'chrpsychs_scr_5a10': '',
'chrpsychs_scr_5a10_on': '',
'chrpsychs_scr_5a6_on': '',
'chrpsychs_scr_6a10': '',
'chrpsychs_scr_6a10_on': '',
'chrpsychs_scr_6a6_on': '',
'chrpsychs_scr_7a10': '',
'chrpsychs_scr_7a10_on': '',
'chrpsychs_scr_7a6_on': '',
'chrpsychs_scr_8a10': '',
'chrpsychs_scr_8a10_on': '',
'chrpsychs_scr_8a6_on': '',
'chrpsychs_scr_9a10': 0,
'chrpsychs_scr_9a10_on': '',
'chrpsychs_scr_9a6_on': '2021-01-01',
'chrpsychs_scr_10a10': '',
'chrpsychs_scr_10a10_on': '',
'chrpsychs_scr_10a6_on': '',
'chrpsychs_scr_11a10': '',
'chrpsychs_scr_11a10_on': '',
'chrpsychs_scr_11a6_on': '',
'chrpsychs_scr_12a10': '',
'chrpsychs_scr_12a10_on': '',
'chrpsychs_scr_12a6_on': '',
'chrpsychs_scr_13a10': '',
'chrpsychs_scr_13a10_on': '',
'chrpsychs_scr_13a6_on': '',
'chrpsychs_scr_14a10': '',
'chrpsychs_scr_14a10_on': '',
'chrpsychs_scr_14a6_on': '',
'chrpsychs_scr_15a10': '',
'chrpsychs_scr_15a10_on': '',
'chrpsychs_scr_15a6_on': ''}
sum1=0
min_a10_on='3000-01-01'
min_a6_on='3000-01-01'
for i in range(1,16):
v=dict1[f'chrpsychs_scr_{i}a10']
if v:
sum1+=v
v=dict1[f'chrpsychs_scr_{i}a10_on']
if v:
min_a10_on=min(min_a10_on,v)
v=dict1[f'chrpsychs_scr_{i}a6_on']
if v:
min_a6_on=min(min_a6_on,v)
value=''
if sum1>0 and min_a10_on < min_a6_on:
value=1
elif sum1==0 or min_a10_on >= min_a6_on:
value=0
print('chrpsychs_scr_ac8:',value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment