Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_repr(self):
self.assertEqual(ContextBase().__repr__(), 'ContextBase({})')
def test_classes(self):
test_eventer = TestEventer()
conn = RWSConnection('innovate', "FAKE_USER", "FAKE_PASS")
ODMAdapter(conn, "Mediflex", "Dev", test_eventer)
def autofill(ctx, steps, metadata, fixed, study, environment, subject):
"""Request enterable data for a subject, generate data values and post back to Rave.
Requires 'rwscmd_getdata' configurable dataset to be installed on the Rave URL."""
if metadata is not None: # Read metadata from file, if supplied
odm_metadata = metadata.read()
meta_v = etree.fromstring(odm_metadata).find('.//' + E_ODM.METADATA_VERSION.value).get(A_ODM.OID.value)
else:
odm_metadata = None
meta_v = None
fixed_values = {}
if fixed is not None: # Read fixed values from file, if supplied
for f in fixed:
oid, value = f.decode().split(',')
fixed_values[oid] = value
if ctx.obj['VERBOSE']:
click.echo('Fixing {} to value: {}'.format(oid, value))
try:
for n in range(0, steps):
if ctx.obj['VERBOSE']:
click.echo('Step {}'.format(str(n + 1)))
if __name__ == '__main__':
#An example
logging.basicConfig(level=logging.INFO)
from rwslib._settings import accounts
#Accounts is a dict of dicts like
# accounts = {'innovate' : {'username': 'username',
# 'password':'password'},
# 'otherurl' : {'username': 'username',
# 'password':'password'},
# }
acc = accounts['innovate']
rv = RWSConnection('innovate', acc['username'], acc['password'])
path, _ = os.path.split(os.path.realpath(__file__))
db_path = os.path.join(path, 'local_cvs.db')
#Make sqllite connection
logging.info('Opening/overwriting sqllite db %s' % db_path)
conn = sqlite3.connect(db_path)
#DBAdaptor takes care of all the database specific parts of the process
db_adaptor = SQLLiteDBAdapter(conn)
lcv = LocalCVBuilder(rv, 'SIMPLESTUDY', 'TEST', db_adaptor)
lcv.execute()
for step in self.check_steps:
step.build(builder)
for action in self.check_actions:
action.build(builder)
builder.end('mdsol:EditCheckDef')
def __lshift__(self, other):
"""Override << operator"""
if not isinstance(other, (MdsolCheckStep, MdsolCheckAction,)):
raise ValueError('EditCheck cannot accept a {0} as a child element'.format(other.__class__.__name__))
self.set_list_attribute(other, MdsolCheckStep, 'check_steps')
self.set_list_attribute(other, MdsolCheckAction, 'check_actions')
class MdsolConfirmationMessage(ODMElement):
"""
Form is saved confirmation message
.. note:: this is a Medidata Rave Specific Element
"""
def __init__(self, message, lang=None):
"""
:param str message: Content of confirmation message
:param str lang: Language declaration for Message
"""
self.message = message
self.lang = lang
def build(self, builder):
"""Build XML by appending to builder"""
builder.end("AdminData")
def __lshift__(self, other):
"""Override << operator"""
if not isinstance(other, (User, Location,)):
raise ValueError('{0} cannot accept a {1} as a child element'.format(self.__class__.__name__,
other.__class__.__name__))
self.set_list_attribute(other, User, 'users')
self.set_list_attribute(other, Location, 'locations')
return other
class MetaDataVersionRef(ODMElement):
"""
A reference to a MetaDataVersion used at the containing Location.
The EffectiveDate expresses the fact that the metadata used at a location can vary over time.
"""
def __init__(self, study_oid, metadata_version_oid, effective_date):
"""
:param str study_oid: References the :class:`Study` that uses this metadata version.
:param str metadata_version_oid: References the :class:`rwslib.builders.MetaDataVersion` (within the above Study).
:param datetime.datetime effective_date: Effective Date for this version and Site
"""
super(MetaDataVersionRef, self).__init__()
self.study_oid = study_oid
self.metadata_version_oid = metadata_version_oid
self.effective_date = effective_date
def build(self, builder):
if value in (None, '') or value.strip() == "":
raise AttributeError("Empty CodeListOID value is invalid.")
self._codelist_oid = value
def build(self, builder):
"""
Build XML by appending to builder
"""
if self.codelist_oid is None:
raise ValueError("CodeListOID not set.")
builder.start("FlagType", dict(CodeListOID=self.codelist_oid))
builder.data(self.flag_type)
builder.end("FlagType")
class FlagValue(ODMElement):
"""
The value of the flag. The meaning of this value is typically dependent on the associated FlagType.
The actual value must be a member of the referenced CodeList.
.. note:: FlagValue is not supported by Rave
"""
def __init__(self, flag_value, codelist_oid=None):
"""
:param flag_value: Value for :class:`Flag`
"""
self.flag_value = flag_value
self._codelist_oid = None
if codelist_oid is not None:
self.codelist_oid = codelist_oid
if value in (None, '') or value.strip() == "":
raise AttributeError("Empty CodeListOID value is invalid.")
self._codelist_oid = value
def build(self, builder):
"""
Build XML by appending to builder
"""
if self.codelist_oid is None:
raise ValueError("CodeListOID not set.")
builder.start("FlagValue", dict(CodeListOID=self.codelist_oid))
builder.data(self.flag_value)
builder.end("FlagValue")
class UserRef(ODMElement):
"""
Reference to a :class:`User`
"""
def __init__(self, oid):
"""
:param str oid: OID for referenced :class:`User`
"""
self.oid = oid
def build(self, builder):
"""
Build XML by appending to builder
"""
builder.start("UserRef", dict(UserOID=self.oid))
builder.end("UserRef")
def __init__(self, reason):
"""
:param str reason: Supplied Reason for change
"""
self.reason = reason
def build(self, builder):
"""
Build XML by appending to builder
"""
builder.start("ReasonForChange", {})
builder.data(self.reason)
builder.end("ReasonForChange")
class DateTimeStamp(ODMElement):
"""
The date/time that the data entry, modification, or signature was performed.
This applies to the initial occurrence of the action, not to subsequent transfers between computer systems.
"""
def __init__(self, date_time):
#: specified DateTime for event
self.date_time = date_time
def build(self, builder):
"""
Build XML by appending to builder
"""
builder.start("DateTimeStamp", {})
if isinstance(self.date_time, datetime):
builder.data(dt_to_iso8601(self.date_time))
#: TransactionType for the Attribute
self.transaction_type = transaction_type
def build(self, builder):
"""Build XML by appending to builder"""
params = dict(Namespace=self.namespace,
Name=self.name,
Value=self.value,
TransactionType=self.transaction_type,
)
builder.start('mdsol:Attribute', params)
builder.end('mdsol:Attribute')
class MdsolCustomFunctionDef(ODMElement):
"""
Extension for Rave Custom functions
.. note:: This is a Medidata Rave Specific Extension
.. note:: VB was deprecated in later Rave versions.
"""
VB = "VB" # VB was deprecated in later Rave versions.
C_SHARP = "C#"
SQL = "SQ"
VALID_LANGUAGES = [C_SHARP, SQL, VB]
def __init__(self, oid, code, language="C#"):
"""
:param str oid: OID for CustomFunction
:param str code: Content for the CustomFunction
:param str language: Language for the CustomFunction