in clns-eTarget_ingest/clinicaldata.py [0:0]
def getPatientDetails(self, row):
# Patient data from the file
patientDetails = {'hospital_numberNo':row[0],
'patientNumber':row[1],
'ageOfConsent':row[2],
'gender':row[3],
'dateOfDiagnosis':row[4],
'primaryTumourType':row[5].replace("'", "''"),
'stage':row[6],
'dateOfConsent':row[7],
'dateOfBloodCollection':row[9],
'sampleType':row[10],
'sampleDate':row[11],
'biopsyLocation':row[12].replace("'", "''"),
'gdlRequestDate':row[13],
'treatmentDetails':row[14].replace("'", "''"),
'treatmentStartDate':row[15],
'treatmentEndDate':row[16],
'consultant':row[17].replace("'", "''"),
'updateStamp':row[18],
'preclinId':row[19].replace("'", "''"),
'tumourId':row[20].replace("'", "''"),
'addInfo':row[21].replace("'", "''")}
if len(patientDetails['ageOfConsent'].strip())==0 :
raise Exception('Age at consent cannot be empty')
if not patientDetails['ageOfConsent'].isdigit() :
raise Exception('Age at consent is not a number')
if len(patientDetails['dateOfConsent'].strip())==0:
raise Exception('Date of Consent cannot be empty')
if len(patientDetails['gender'].strip())==0:
raise Exception('Gender cannot be empty')
if len(patientDetails['patientNumber'].strip())==0:
raise Exception('Patient ID cannot be empty')
if len(patientDetails['dateOfDiagnosis'].strip())==0:
raise Exception('Date of diagnosis cannot be empty')
if len(patientDetails['consultant'].strip())==0:
raise Exception('Consultant cannot be empty')
if len(patientDetails['primaryTumourType'].strip())==0:
raise Exception('Diagnosis cannot be empty')
if len(patientDetails['sampleType'].strip())==0 and (len(patientDetails['sampleDate'].strip())>0 or len(row[22].strip())>0 or len(patientDetails['biopsyLocation'].strip())>0):
raise Exception('Sample type cannot be empty if other tumour data are present')
if len(patientDetails['treatmentDetails'].strip())==0 and (len(patientDetails['treatmentStartDate'].strip())>0 or len(patientDetails['treatmentEndDate'].strip())>0):
raise Exception('treatments require a name')
if len(row[8].strip())>1:
self.checkTimePoint(row[8], 'blood', patientDetails['patientNumber'])
patientDetails['sampleTimePoint'] = row[8][1:]
if len(patientDetails['dateOfBloodCollection'].strip())==0:
raise Exception('Date of blood collection cannot be empty if there is a time point')
elif len(patientDetails['dateOfBloodCollection'].strip())>0:
raise Exception('Blood timepoint cannot be empty if other blood data are available')
else:
patientDetails['sampleTimePoint'] = ''
if len(row[22].strip())>1:
self.checkTimePoint(row[22].strip(), 'tumour', patientDetails['patientNumber'])
patientDetails['tumourTimePoint'] = row[22][2:]
if len(patientDetails['preclinId'].strip()) ==0:
patientDetails['preclinId']=patientDetails['patientNumber']+row[22]
else:
if patientDetails['sampleType'].upper()!='CDX' and patientDetails['sampleType'].upper()!='PDX' and len(patientDetails['sampleDate'].strip()) > 0:
raise Exception('Tumour timepoint cannot be empty if other tumour data are available')
patientDetails['tumourTimePoint']=''
f = "%d/%m/%Y"
f2 = "%d/%m/%Y %H:%M"
try:
datetime.strptime(patientDetails['dateOfDiagnosis'], f)
datetime.strptime(patientDetails['dateOfConsent'], f)
if patientDetails['dateOfBloodCollection'].strip()!='':
datetime.strptime(patientDetails['dateOfBloodCollection'], f)
if patientDetails['sampleDate'].strip()!='':
datetime.strptime(patientDetails['sampleDate'], f)
if patientDetails['treatmentStartDate'].strip()!='':
datetime.strptime(patientDetails['treatmentStartDate'], f)
if patientDetails['treatmentEndDate'].strip()!='':
datetime.strptime(patientDetails['treatmentEndDate'], f)
except ValueError as e:
raise Exception('Date format is incorrect and does not match dd/mm/yyyy or is not a valid date')
try:
if patientDetails['updateStamp'].strip()!='':
datetime.strptime(patientDetails['updateStamp'], f2)
except ValueError as e:
try:
datetime.strptime(patientDetails['updateStamp'], f)
except ValueError as e:
raise Exception('Date format is incorrect and does not match dd/mm/yyyy HH:MM or is not a valid date')
return patientDetails