text
stringlengths
81
112k
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" builder.start("GlobalVariables", {}) make_element(builder, "StudyName", self.name) make_element(builder, "StudyDescription", self.description) make_element(builder, "ProtocolName"...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" builder.start("BasicDefinitions", {}) for child in self.measurement_units: child.build(builder) builder.end("BasicDefinitions")
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(OID=self.oid, Name=self.name) if self.unit_dictionary_name: params["mdsol:UnitDictionaryName"] = self.unit_dictionary_name for suffix in ["A", "B", "C", "K"]:...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" builder.start("Symbol", {}) for child in self.translations: child.build(builder) builder.end("Symbol")
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = {} if self.lang is not None: params["xml:lang"] = self.lang builder.start("TranslatedText", params) builder.data(self.text) builder.end("TranslatedTex...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(OID=self.oid, Name=self.name) if self.description is not None: params["Description"] = self.description if self.signature_prompt is not None: para...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" builder.start("Protocol", {}) for child in self.study_event_refs: child.build(builder) for alias in self.aliases: alias.build(builder) builder.end("Protoco...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(StudyEventOID=self.oid, Mandatory=bool_to_yes_no(self.mandatory)) if self._order_number is not None: params["OrderNumber"] = self._order_number builder.start("St...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict( OID=self.oid, Name=self.name, Repeating=bool_to_yes_no(self.repeating), Type=self.event_type, ) if self.category is not No...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict( OID=self.oid, Name=self.name, Repeating=bool_to_yes_no(self.repeating) ) if self.order_number is not None: params["mdsol:OrderNumber"] = str(self.o...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict( OID=self.oid, Name=self.name, Repeating=bool_to_yes_no(self.repeating), IsReferenceData=bool_to_yes_no(self.is_reference_data), ) ...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(ItemOID=self.oid, Mandatory=bool_to_yes_no(self.mandatory)) if self.order_number is not None: params["OrderNumber"] = str(self.order_number) if self.key_seque...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict( OID=self.oid, Name=self.name, DataType=self.datatype.value, Length=str(self.length), ) if self.date_time_format is not Non...
Build XML by appending to builder .. note:: Questions can contain translations def build(self, builder): """ Build XML by appending to builder .. note:: Questions can contain translations """ builder.start("Question", {}) for translation in self.translations: ...
sets the comparator (with validation of input) def comparator(self, value): """sets the comparator (with validation of input)""" if not isinstance(value, RangeCheckComparatorType): raise AttributeError("%s comparator is invalid in RangeCheck." % (value,)) self._comparator = value
sets the Soft or Hard range setting (with validation of input) def soft_hard(self, value): """sets the Soft or Hard range setting (with validation of input)""" if not isinstance(value, RangeCheckType): raise AttributeError("%s soft_hard invalid in RangeCheck." % (value,)) self._soft...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(SoftHard=self.soft_hard.value, Comparator=self.comparator.value) builder.start("RangeCheck", params) if self.check_value is not None: self.check_value.build(buil...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" builder.start("CheckValue", {}) builder.data(str(self.value)) builder.end("CheckValue")
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(OID=self.oid, Name=self.name, DataType=self.datatype.value) if self.sas_format_name is not None: params["SASFormatName"] = self.sas_format_name builder.start("Co...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(CodedValue=self.coded_value) if self.order_number is not None: params["mdsol:OrderNumber"] = str(self.order_number) if self.specify: params["mdsol:S...
Build this item :param builder: :return: def build(self, builder): """ Build this item :param builder: :return: """ params = dict(Context=self.context, Name=self.name) builder.start("Alias", params) builder.end("Alias")
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(LabelOID=self.oid, OrderNumber=str(self.order_number)) builder.start("mdsol:LabelRef", params) builder.end("mdsol:LabelRef")
Build XML by appending to builder 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:A...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(OID=self.oid, Language=self.language) builder.start("mdsol:CustomFunctionDef", params) builder.data(self.code) builder.end("mdsol:CustomFunctionDef")
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict( OID=self.oid, Active=bool_to_true_false(self.active), BypassDuringMigration=bool_to_true_false(self.bypass_during_migration), NeedsRetesting...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict() if self.variable_oid is not None: params["VariableOID"] = self.variable_oid if self.data_format is not None: params["DataFormat"] = self.data_for...
Set the value for the CheckActionType, validating input def check_action_type(self, value): """Set the value for the CheckActionType, validating input""" if value is not None: if not isinstance(value, ActionType): raise AttributeError("Invalid check action %s" % value) ...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict( OID=self.oid, Active=bool_to_true_false(self.active), BypassDuringMigration=bool_to_true_false(self.bypass_during_migration), NeedsRetesting...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(OID=self.oid, Name=self.name) if self.field_number is not None: params["FieldNumber"] = str(self.field_number) builder.start("mdsol:LabelDef", params) ...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" builder.start("mdsol:ReviewGroup", {}) builder.data(self.name) builder.end("mdsol:ReviewGroup")
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(MetaDataVersionOID=str(self.metadata_version_oid), StudyOID="%s (%s)" % (self.projectname, self.environment,), ) # mixins self.m...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(SubjectKey=self.subject_key) params['mdsol:SubjectKeyType'] = self.subject_key_type if self.transaction_type is not None: params["TransactionType"] = self.trans...
Build XML by appending to builder :Example: <StudyEventData StudyEventOID="SCREENING" StudyEventRepeatKey="1" TransactionType="Update"> def build(self, builder): """Build XML by appending to builder :Example: <StudyEventData StudyEventOID="SCREENING" StudyEventRepeatKey="1" Tran...
Build XML by appending to builder :Example: <FormData FormOID="MH" TransactionType="Update"> def build(self, builder): """Build XML by appending to builder :Example: <FormData FormOID="MH" TransactionType="Update"> """ params = dict(FormOID=self.formoid) ...
Build XML by appending to builder def build(self, builder, formname=None): """Build XML by appending to builder""" params = dict(ItemGroupOID=formname if formname else self.itemgroupoid) if self.transaction_type is not None: params["TransactionType"] = self.transaction_type ...
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ params = dict(ItemOID=self.itemoid) if self.transaction_type is not None: params["TransactionType"] = self.transaction_type if self.value in [None, '']: ...
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ params = {} if self.signature_id is not None: # If a Signature element is contained within a Signatures element, the ID attribute is required. params['I...
Set ID for Annotation def annotation_id(self, value): """Set ID for Annotation""" if value in [None, ''] or str(value).strip() == '': raise AttributeError("Invalid ID value supplied") self._id = value
Set SeqNum for Annotation :param value: SeqNum value :type value: int def seqnum(self, value): """ Set SeqNum for Annotation :param value: SeqNum value :type value: int """ if not re.match(r'\d+', str(value)) or value < 0: raise AttributeError...
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ params = {} # Add in the transaction type if self.transaction_type is not None: params["TransactionType"] = self.transaction_type if self.seqnum is...
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ builder.start("Annotations") # populate the flags for annotation in self.annotations: annotation.build(builder) builder.end("Annotations")
Set Text content for Comment (validation of input) def text(self, value): """Set Text content for Comment (validation of input)""" if value in (None, '') or value.strip() == "": raise AttributeError("Empty text value is invalid.") self._text = value
Set Originator with validation of input def sponsor_or_site(self, value): """Set Originator with validation of input""" if value not in Comment.VALID_SPONSOR_OR_SITE_RESPONSES: raise AttributeError("%s sponsor_or_site value of %s is not valid" % (self.__class__.__name__, ...
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ if self.text is None: raise ValueError("Text is not set.") params = {} if self.sponsor_or_site is not None: params['SponsorOrSite'] = self.sponso...
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ builder.start("Flag", {}) if self.flag_type is not None: self.flag_type.build(builder) if self.flag_value is None: raise ValueError('FlagValue ...
Build XML by appending to builder 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...
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ builder.start("UserRef", dict(UserOID=self.oid)) builder.end("UserRef")
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ builder.start("LocationRef", dict(LocationOID=str(self.oid))) builder.end("LocationRef")
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ params = dict(LocationOID=self.oid) # mixins self.mixin() self.mixin_params(params) builder.start("SiteRef", params) builder.end("SiteRef")
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ builder.start("SignatureRef", dict(SignatureOID=self.oid)) builder.end("SignatureRef")
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ builder.start("ReasonForChange", {}) builder.data(self.reason) builder.end("ReasonForChange")
Build XML by appending to builder 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)) else: builder.data(self.d...
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ builder.start("SourceID", {}) builder.data(self.source_id) builder.end("SourceID")
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = {} if self.edit_point is not None: params["EditPoint"] = self.edit_point if self.used_imputation_method is not None: params['UsedImputationMethod'] = bo...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(Value=self.value, Status=self.status.value, ProtocolDeviationRepeatKey=self.repeat_key ) if self.code: ...
Set Query Status def status(self, value): """Set Query Status""" if value is not None: if not isinstance(value, QueryStatusType): raise AttributeError("%s action type is invalid in mdsol:Query." % (value,)) self._status = value
Build XML by appending to builder def build(self, builder): """ Build XML by appending to builder """ params = {} if self.value is not None: params['Value'] = str(self.value) if self.query_repeat_key is not None: params['QueryRepeatKey'] = str(s...
Build XML object, return the root def getroot(self): """Build XML object, return the root""" builder = ET.TreeBuilder() self.build(builder) return builder.close()
Build XML object, return the root, this is a copy for consistency and testing def build(self, builder): """Build XML object, return the root, this is a copy for consistency and testing""" params = dict(ODMVersion="1.3", FileType=self.filetype, CreationDateTim...
Additional keyword arguments def _querystring(self): """Additional keyword arguments""" kw = {"studyoid": self.studyoid} if self.location_oid is not None: kw["locationoid"] = self.location_oid return kw
Normalise the Attribute value and return .. note: `datetime` objects are normalised to ISO datestring, `bool` objects are normalised to Yes or No :rtype: str :return: The normalised value def value(self): """ Normalise the Attribute value and return .. note: `datetime` ...
Add an attribute to the current instance :param str attribute: Attribute name :type value: Union[datetime,bool,str] :param value: Attribute value def add_attribute(self, attribute, value): """ Add an attribute to the current instance :param str attribute: Attribute nam...
Merge in the MdsolAttribute for the passed parameter :param dict params: dictionary of object parameters def mixin_params(self, params): """ Merge in the MdsolAttribute for the passed parameter :param dict params: dictionary of object parameters """ if not isinstance(p...
Setter for the last_update_time attribute :param datetime.datetime value: value to set for the element def last_update_time(self, value): """ Setter for the last_update_time attribute :param datetime.datetime value: value to set for the element """ if isinstance(value,...
Set the Update Time from the local clock (in UTC) def set_update_time(self, update_time=None): """ Set the Update Time from the local clock (in UTC) """ if update_time and isinstance(update_time, (datetime.datetime,)): self.last_update_time = update_time else: ...
Add the mdsol:LastUpdateTime attribute :return: def mixin_params(self, params): """ Add the mdsol:LastUpdateTime attribute :return: """ super(LastUpdateMixin, self).mixin_params(params) if self.last_update_time is not None: params.update({"mdsol:Last...
Add a milestone :param codelistoid: specify the CodeListOID (defaults to MILESTONES) :param str milestone: Milestone to add def add_milestone(self, milestone, codelistoid="MILESTONES"): """ Add a milestone :param codelistoid: specify t...
Add the annotations to the ODM Element (if defined) :return: def mixin(self): """ Add the annotations to the ODM Element (if defined) :return: """ if self.milestones: from rwslib.builders.clinicaldata import Annotation, Flag, FlagValue annotation...
Extract environment name using studyname and protocolname to guide :param str studyname: Name of the study (including Env) :param str protocolname: Name of the study def getEnvironmentFromNameAndProtocol(studyname, protocolname): """ Extract environment name using studyname and protocolname to guide ...
Parse XML string, return root :param str: Passed in XML def parseXMLString(xml): """ Parse XML string, return root :param str: Passed in XML """ # Remove BOM if it exists (different requests seem to have different BOMs) unichr_captured = "" if not xml.strip(): return u"" ...
Read properties from an XML Element to build a StudyList Item :param lxml.etree.Element elem: The source Study XML Element .. code-block:: xml <Study OID="Fixitol(Dev)" mdsol:ProjectType="GlobalLibraryVolume"> <GlobalVariables> <StudyName>Fixitol (Dev)<...
Read properties from a MetaDataVersion element :param lxml.etree._Element elem: Source etree Element def fromElement(cls, elem): """ Read properties from a MetaDataVersion element :param lxml.etree._Element elem: Source etree Element """ self = cls() self.oid...
Get the subject name consistently :rtype str :return: The Subject ID for the subject .. note:: * If the `SubjectKeyType` is `SubjectUUID` then the subject name lives in the `mdsol:SubjectName` attribute * If the `SubjectKeyType` is `SubjectName` then the subject name lives i...
Read properties from an XML Element def fromElement(cls, elem): """ Read properties from an XML Element """ self = cls() self.studyoid = elem.get("StudyOID") self.metadataversionoid = elem.get("MetaDataVersionOID") e_subjectdata = elem.findall(ODM_NS + "SubjectDa...
Make an element with this tag and text content def make_element(builder, tag, content): """Make an element with this tag and text content""" builder.start(tag, {}) builder.data(content) # Must be UTF-8 encoded builder.end(tag)
Used to set guard the setting of an attribute which is singular and can't be set twice def set_single_attribute(self, other, trigger_klass, property_name): """Used to set guard the setting of an attribute which is singular and can't be set twice""" if isinstance(other, trigger_klass): # C...
Used to set guard the setting of a list attribute, ensuring the same element is not added twice. def set_list_attribute(self, other, trigger_klass, property_name): """Used to set guard the setting of a list attribute, ensuring the same element is not added twice.""" # Check property exists if i...
Set the TransactionType (with Input Validation) def transaction_type(self, value): """Set the TransactionType (with Input Validation)""" if value is not None: if value not in self.ALLOWED_TRANSACTION_TYPES: raise AttributeError('%s transaction_type element must be one of %s ...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = {} if self.study_oid: params.update(dict(StudyOID=self.study_oid)) builder.start("AdminData", params) for user in self.users: user.build(builder) ...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(StudyOID=self.study_oid, MetaDataVersionOID=self.metadata_version_oid, EffectiveDate=dt_to_iso8601(self.effective_date)) builder.start("M...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(OID=self.oid, Name=self.name) if self.location_type: params.update(dict(LocationType=self.location_type.value)) # mixins self.mixin...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict() builder.start(self.__class__.__name__, params) for street in self.street_names: street.build(builder) # build the children for child in ('city'...
Build XML by appending to builder def build(self, builder): """Build XML by appending to builder""" params = dict(OID=self.oid) if self.user_type: params.update(dict(UserType=self.user_type.value)) builder.start(self.__class__.__name__, params) # build the children ...
Build this element :param builder: :return: def build(self, builder): """ Build this element :param builder: :return: """ builder.start(self.__class__.__name__) builder.data(self.country_code) builder.end(self.__class__.__name__)
If link for next result set has been passed, extract it and get the next set start id def get_next_start_id(self): """If link for next result set has been passed, extract it and get the next set start id""" link = self.rws_connection.last_result.links.get("next", None) if link: link...
Send request to RWS endpoint. The request object passed provides the URL endpoint and the HTTP method. Takes the text response from RWS and allows the request object to modify it for return. This allows the request object to return text, an XML document object, a CSV file or anything else that can...
Test demonstrating building clinical data def example_clinical_data(study_name, environment): """Test demonstrating building clinical data""" odm = ODM("test system")( ClinicalData("Mediflex", "DEV")( SubjectData("MDSOL", "IJS TEST4", transaction_type="Insert")( StudyEventData("S...
Example of building a metadata doc def example_metadata(study_name, draft_name): """Example of building a metadata doc""" odm = ODM("SYSTEM_NAME", filetype=ODM.FILETYPE_SNAPSHOT) study = Study(study_name, project_type=Study.PROJECT) # Push study element into odm odm << study # Create global ...
Take a Rave CSV output ending with a line with just EOF on it and return a DictReader def getCSVReader(data, reader_type=csv.DictReader): """Take a Rave CSV output ending with a line with just EOF on it and return a DictReader""" f = StringIO(data[:-4]) # Remove \nEOF return reader_type(f)
Extract dataset definitions from CSV metadata def _setDatasets(self, metadata): """Extract dataset definitions from CSV metadata""" # Pull the lot into a list cols = list(self.getCSVReader(metadata)) # sort the cols by view name and ordinal (they come sorted, but lets be sure) ...
Take a string of form data as CSV and convert to insert statements, return template and data values def processFormData(self, data, dataset_name): """Take a string of form data as CSV and convert to insert statements, return template and data values""" # Get the cols for this dataset cols = se...
Generate and process table SQL, SQLLite version def _processDDL(self): """Generate and process table SQL, SQLLite version""" sql_statements = self._generateDDL() logging.info('Generating sqllite tables') for stmt in sql_statements: c = self.conn.cursor() c.execu...
Generate DDL statements for SQLLite def _generateDDL(self): """Generate DDL statements for SQLLite""" sql = [] # Next convert each set of columns into a table structure for dataset_name in sorted(self.datasets.keys()): # SQL to drop the table if it already exists ...
Overridden version of create DML for SQLLite def _processDML(self, dataset_name, cols, reader): """Overridden version of create DML for SQLLite""" sql_template = self._generateInsertStatement(dataset_name, cols) # Now insert in batch, reader is a list of rows to insert at this point c ...
Generates a sql INSERT template def _generateInsertStatement(self, dataset_name, cols): """Generates a sql INSERT template""" col_names = [col["varname"] for col in cols] # Generate question mark placeholders qms = ','.join(['?' for x in col_names]) return 'INSERT INTO %s (%s)...
Have format V_<studyname>_<view>[_RAW], return name and view type REGULAR or RAW def name_type_from_viewname(viewname): """Have format V_<studyname>_<view>[_RAW], return name and view type REGULAR or RAW""" matched = VIEW_REX.match(viewname) return matched.group('view'), matched.group('type') o...
Generate local DB, pulling metadata and data from RWSConnection def execute(self): """Generate local DB, pulling metadata and data from RWSConnection""" logging.info('Requesting view metadata for project %s' % self.project_name) project_csv_meta = self.rws_connection.send_request(ProjectMetaDa...
Function to duck-type values, not relying on standard Python functions because, for example, a string of '1' should be typed as an integer and not as a string or float since we're trying to replace like with like when scrambling. def typeof_rave_data(value): """Function to duck-type values, not relying on ...
Return random float in specified format def scramble_float(self, length, sd=0): """Return random float in specified format""" if sd == 0: return str(fake.random_number(length)) else: return str(fake.pyfloat(length - sd, sd, positive=True))
Return random date def scramble_date(self, value, format='%d %b %Y'): """Return random date """ # faker method signature changed if value == '': # handle the empty string by defaulting to 'now' and 1 year ago end_date = 'now' start_date = '-1y' else: ...