Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# for elem in self.metadata.iter(E_ODM.ITEM_DEF.value):
datatype = elem.get(A_ODM.DATATYPE.value)
codelist = None
for el in elem.iter(E_ODM.CODELIST_REF.value):
codelist = el.get(A_ODM.CODELIST_OID.value)
length = 1 if not A_ODM.LENGTH in elem else int(elem.get(A_ODM.LENGTH.value))
if A_ODM.SIGNIFICANT_DIGITS.value in elem.keys():
sd = elem.get(A_ODM.SIGNIFICANT_DIGITS.value)
else:
sd = 0
if A_ODM.DATETIME_FORMAT.value in elem.keys():
dt_format = elem.get(A_ODM.DATETIME_FORMAT.value)
for fmt in [('yyyy', '%Y'), ('MMM', '%b'), ('dd', '%d'), ('HH', '%H'), ('nn', '%M'), ('ss', '%S'),
('-', '')]:
dt_format = dt_format.replace(fmt[0], fmt[1])
if codelist is not None:
return self.scramble_codelist(codelist)
elif datatype == 'integer':
return self.scramble_int(length)
elif datatype == 'float':
return self.scramble_float(length, sd)
elif datatype in ['string', 'text']:
return self.scramble_string(length)
def scramble_itemdata(self, oid, value):
"""If metadata provided, use it to scramble the value based on data type"""
if self.metadata is not None:
path = ".//{0}[@{1}='{2}']".format(E_ODM.ITEM_DEF.value, A_ODM.OID.value, oid)
elem = self.metadata.find(path)
# for elem in self.metadata.iter(E_ODM.ITEM_DEF.value):
datatype = elem.get(A_ODM.DATATYPE.value)
codelist = None
for el in elem.iter(E_ODM.CODELIST_REF.value):
codelist = el.get(A_ODM.CODELIST_OID.value)
length = 1 if not A_ODM.LENGTH in elem else int(elem.get(A_ODM.LENGTH.value))
if A_ODM.SIGNIFICANT_DIGITS.value in elem.keys():
sd = elem.get(A_ODM.SIGNIFICANT_DIGITS.value)
else:
sd = 0
if A_ODM.DATETIME_FORMAT.value in elem.keys():
dt_format = elem.get(A_ODM.DATETIME_FORMAT.value)
for fmt in [('yyyy', '%Y'), ('MMM', '%b'), ('dd', '%d'), ('HH', '%H'), ('nn', '%M'), ('ss', '%S'),
('-', '')]:
def scramble_itemdata(self, oid, value):
"""If metadata provided, use it to scramble the value based on data type"""
if self.metadata is not None:
path = ".//{0}[@{1}='{2}']".format(E_ODM.ITEM_DEF.value, A_ODM.OID.value, oid)
elem = self.metadata.find(path)
# for elem in self.metadata.iter(E_ODM.ITEM_DEF.value):
datatype = elem.get(A_ODM.DATATYPE.value)
codelist = None
for el in elem.iter(E_ODM.CODELIST_REF.value):
codelist = el.get(A_ODM.CODELIST_OID.value)
length = 1 if not A_ODM.LENGTH in elem else int(elem.get(A_ODM.LENGTH.value))
if A_ODM.SIGNIFICANT_DIGITS.value in elem.keys():
sd = elem.get(A_ODM.SIGNIFICANT_DIGITS.value)
else:
sd = 0
if A_ODM.DATETIME_FORMAT.value in elem.keys():
dt_format = elem.get(A_ODM.DATETIME_FORMAT.value)
for fmt in [('yyyy', '%Y'), ('MMM', '%b'), ('dd', '%d'), ('HH', '%H'), ('nn', '%M'), ('ss', '%S'),
('-', '')]:
dt_format = dt_format.replace(fmt[0], fmt[1])
if codelist is not None:
return self.scramble_codelist(codelist)
elif datatype == 'integer':
def scramble_itemdata(self, oid, value):
"""If metadata provided, use it to scramble the value based on data type"""
if self.metadata is not None:
path = ".//{0}[@{1}='{2}']".format(E_ODM.ITEM_DEF.value, A_ODM.OID.value, oid)
elem = self.metadata.find(path)
# for elem in self.metadata.iter(E_ODM.ITEM_DEF.value):
datatype = elem.get(A_ODM.DATATYPE.value)
codelist = None
for el in elem.iter(E_ODM.CODELIST_REF.value):
codelist = el.get(A_ODM.CODELIST_OID.value)
length = 1 if not A_ODM.LENGTH in elem else int(elem.get(A_ODM.LENGTH.value))
if A_ODM.SIGNIFICANT_DIGITS.value in elem.keys():
sd = elem.get(A_ODM.SIGNIFICANT_DIGITS.value)
else:
sd = 0
if A_ODM.DATETIME_FORMAT.value in elem.keys():
dt_format = elem.get(A_ODM.DATETIME_FORMAT.value)
for fmt in [('yyyy', '%Y'), ('MMM', '%b'), ('dd', '%d'), ('HH', '%H'), ('nn', '%M'), ('ss', '%S'),
('-', '')]:
dt_format = dt_format.replace(fmt[0], fmt[1])
if codelist is not None:
return self.scramble_codelist(codelist)
def scramble_itemdata(self, oid, value):
"""If metadata provided, use it to scramble the value based on data type"""
if self.metadata is not None:
path = ".//{0}[@{1}='{2}']".format(E_ODM.ITEM_DEF.value, A_ODM.OID.value, oid)
elem = self.metadata.find(path)
# for elem in self.metadata.iter(E_ODM.ITEM_DEF.value):
datatype = elem.get(A_ODM.DATATYPE.value)
codelist = None
for el in elem.iter(E_ODM.CODELIST_REF.value):
codelist = el.get(A_ODM.CODELIST_OID.value)
length = 1 if not A_ODM.LENGTH in elem else int(elem.get(A_ODM.LENGTH.value))
if A_ODM.SIGNIFICANT_DIGITS.value in elem.keys():
sd = elem.get(A_ODM.SIGNIFICANT_DIGITS.value)
else:
sd = 0
if A_ODM.DATETIME_FORMAT.value in elem.keys():
dt_format = elem.get(A_ODM.DATETIME_FORMAT.value)
for fmt in [('yyyy', '%Y'), ('MMM', '%b'), ('dd', '%d'), ('HH', '%H'), ('nn', '%M'), ('ss', '%S'),
('-', '')]:
dt_format = dt_format.replace(fmt[0], fmt[1])
if codelist is not None:
return self.scramble_codelist(codelist)
elif datatype == 'integer':
return self.scramble_int(length)
elif datatype == 'float':
for n in range(0, steps):
if ctx.obj['VERBOSE']:
click.echo('Step {}'.format(str(n + 1)))
# Get currently enterable fields for this subject
subject_data = get_data(ctx, study, environment, subject)
subject_data_odm = etree.fromstring(subject_data)
if subject_data_odm.find('.//' + E_ODM.CLINICAL_DATA.value) is None:
if ctx.obj['VERBOSE']:
click.echo('No data found')
break
# Get the metadata version for the subject
subject_meta_v = subject_data_odm.find('.//' + E_ODM.CLINICAL_DATA.value).get(
A_ODM.METADATA_VERSION_OID.value)
if subject_meta_v is None:
if ctx.obj['VERBOSE']:
click.echo('Subject not found')
break
# If no metadata supplied, or versions don't match, retrieve metadata from RWS
if meta_v != subject_meta_v:
if ctx.obj['VERBOSE']:
click.echo('Getting metadata version {}'.format(subject_meta_v))
ctx.obj['RWS'].send_request(StudyVersionRequest(study, subject_meta_v))
odm_metadata = ctx.obj['RWS'].last_result.text
meta_v = subject_meta_v
# Generate data values to fill in empty fields
if ctx.obj['VERBOSE']:
click.echo('Generating data')