Skip to content

Instantly share code, notes, and snippets.

@tashrifbillah
Last active July 2, 2024 19:15
Show Gist options
  • Save tashrifbillah/5341bcbd94064cc3d48337f2bd71c19e to your computer and use it in GitHub Desktop.
Save tashrifbillah/5341bcbd94064cc3d48337f2bd71c19e to your computer and use it in GitHub Desktop.
Detect fluid_shipment_anomalies
import pandas as pd
# cd /data/predict1/to_nda/nda-submissions
df=pd.read_csv('blood_saliva_rack_Pronet.csv')
index=[]
for i,row in df.iterrows():
rc=row['Rack Code']
pr=row['Position on Rack']
ic=row['Inventory Code']
flag=False
# Rack Code must contain 2 numbers
if pd.isna(rc) or rc in [' ',-3,-9] or \
sum(c.isdigit() for c in rc)<2:
flag=True
elif pd.isna(pr) or len(pr)>3 or len(pr)<2:
flag=True
# length of Inventory Code is 10-12 characters
elif pd.isna(ic) or len(ic)<10:
flag=True
if flag:
index.append(i)
df1=df.loc[index]
df1.to_csv('anomalous_fluid_shipment.csv',index=False)
#######################################################
# blood rack miscount detection
rack_code='9500011256'
files=glob('PronetYA/raw/*/surveys/*.Pronet.json')
subjects=[]
for file in files:
with open(file) as f:
data=json.load(f)
# print(file)
for d in data:
if 'baseline_arm_' in d['redcap_event_name'] or 'month_2_arm_' in d['redcap_event_name']:
if d['chrblood_rack_barcode'].strip()==rack_code:
subjects.append(d['chric_record_id'])
print(d['chric_record_id'],d['chrblood_drawdate'])
# saliva rack miscount detection
rack_code='ProNET-0812'
files=glob('PronetYA/raw/*/surveys/*.Pronet.json')
subjects=[]
for file in files:
with open(file) as f:
data=json.load(f)
# print(file)
for d in data:
if 'baseline_arm_' in d['redcap_event_name'] or 'month_2_arm_' in d['redcap_event_name']:
# if d['chrsaliva_box1b'].strip()==rack_code:
# if d['chrsaliva_box2b'].strip()==rack_code:
if d['chrsaliva_box3b'].strip()==rack_code:
subjects.append(d['chric_record_id'])
print(d['chric_record_id'],d['chrsaliva_coldate'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment