How to use the rwslib.builders.constants.DataType function in rwslib

To help you get started, we’ve selected a few rwslib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mdsol / rwslib / rwslib / builders / metadata.py View on Github external
self.oid = oid

    def build(self, builder):
        """Build XML by appending to builder"""
        builder.start('CodeListRef', {'CodeListOID': self.oid})
        builder.end('CodeListRef')


class CodeList(ODMElement):
    """
    Defines a discrete set of permitted values for an item.

    .. note:: Equates to a Rave Dictionary
    .. note:: Does not support ExternalCodeList
    """
    VALID_DATATYPES = [DataType.Integer, DataType.Text, DataType.Float, DataType.String]

    def __init__(self, oid, name, datatype, sas_format_name=None):
        """
        :param str oid: CodeList OID
        :param str name: Name of CodeList
        :param str datatype: DataType restricts the values that can appear in the CodeList whether internal or external
            (*integer* | *float* | *text* | *string* )
        :param str sas_format_name: SASFormatName must be a legal SAS format for CodeList
        """
        self.oid = oid
        self.name = name
        if datatype not in CodeList.VALID_DATATYPES:
            raise ValueError("{0} is not a valid CodeList datatype".format(datatype))
        self.datatype = datatype
        self.sas_format_name = sas_format_name
        #: Collection of :class:`CodeListItem`
github mdsol / rwslib / rwslib / builders_example.py View on Github external
ItemRef("AGE", 6)
    )

    # Add the ItemDefs
    meta << ItemDef("SEX", "Gender", DataType.Text, 1, control_type=ControlType.RadioButton
       )(
        Question()(TranslatedText("Gender at Birth")),
        CodeListRef("CL_SEX")
    )
    meta << ItemDef("RACE", "Race", DataType.Text, 2,
                    control_type=ControlType.RadioButtonVertical
                    )(
        Question()(TranslatedText("Race")),
        CodeListRef("CL_RACE")
    )
    meta << ItemDef("RACE_OTH", "RaceOther", DataType.Text, 20) \
           << Question() << TranslatedText("If Race Other, please specify")

    meta << ItemDef("DOB", "DateOfBirth", DataType.Date, 10,
                    control_type=ControlType.DateTime,
                    date_time_format="dd/mm/yyyy"
                    )(
        Question()(TranslatedText("Date of Birth")),
        MdsolHelpText("en","If month unknown, enter January")
    )

    meta << ItemDef("AGE", "Age in Years", DataType.Integer, 4, significant_digits=3, control_type=ControlType.Text
       )(
        Question()(TranslatedText("Age in Years")),
        RangeCheck(RangeCheckComparatorType.GreaterThanEqualTo, RangeCheckType.Soft) (
            CheckValue("18")
        ),
github mdsol / rwslib / rwslib / builders / metadata.py View on Github external
:param str field_number: Number that displays to the right of a field label in Rave EDC to create a numbered list
            on the form. - *Rave Specific Attribute*
        :param variable_oid: OID for Variable - *Rave Specific Attribute*
        """
        self.oid = oid
        self.name = name

        if datatype not in ItemDef.VALID_DATATYPES:
            raise AttributeError('{0} is not a valid datatype!'.format(datatype))

        if control_type is not None:
            if not isinstance(control_type, ControlType):
                raise AttributeError("{0} is not a valid Control Type".format(control_type))

        if length is None:
            if datatype in [DataType.DateTime, DataType.Time, DataType.Date]:
                # Default this
                length = len(date_time_format)
            else:
                raise AttributeError('length must be set for all datatypes except Date/Time types')

        self.datatype = datatype
        self.length = length
        self.significant_digits = significant_digits
        self.sas_field_name = sas_field_name
        self.sds_var_name = sds_var_name
        self.origin = origin
        self.comment = comment
        self.active = active
        self.control_type = control_type
        self.acceptable_file_extensions = acceptable_file_extensions
        self.indent_level = indent_level
github mdsol / rwslib / rwslib / builders / metadata.py View on Github external
def __lshift__(self, other):
        """ItemRef can accept MdsolAttribute(s)"""
        if not isinstance(other, (MdsolAttribute)):
            raise ValueError('ItemRef cannot accept a {0} as a child element'.format(other.__class__.__name__))
        self.set_list_attribute(other, MdsolAttribute, 'attributes')
        return other


class ItemDef(ODMElement):
    """
    An ItemDef describes a type of item that can occur within a study.
    Item properties include name, datatype, measurement units, range or codelist restrictions,
    and several other properties.
    """
    VALID_DATATYPES = [DataType.Text, DataType.Integer, DataType.Float, DataType.Date,
                       DataType.DateTime, DataType.Time]

    def __init__(self, oid, name, datatype,
                 length=None,
                 significant_digits=None,
                 sas_field_name=None,
                 sds_var_name=None,
                 origin=None,  # Not mapped in Rave
                 comment=None,
                 active=True,
                 control_type=None,
                 acceptable_file_extensions=None,
                 indent_level=0,
                 source_document_verify=False,
                 default_value=None,
                 sas_format=None,
github mdsol / rwslib / rwslib / builders_example.py View on Github external
# Define item group
    meta << ItemGroupDef("DM_IG1", "DM Item Group 1")(
        MdsolLabelRef("LBL1", 1),
        ItemRef("SEX", 2)(
            MdsolAttribute("Standards","CDASH","SEX"),
            MdsolAttribute("Standards","STDNUMBER","1120")
        ),
        ItemRef("RACE", 3),
        ItemRef("RACE_OTH", 4),
        ItemRef("DOB", 5),
        ItemRef("AGE", 6)
    )

    # Add the ItemDefs
    meta << ItemDef("SEX", "Gender", DataType.Text, 1, control_type=ControlType.RadioButton
       )(
        Question()(TranslatedText("Gender at Birth")),
        CodeListRef("CL_SEX")
    )
    meta << ItemDef("RACE", "Race", DataType.Text, 2,
                    control_type=ControlType.RadioButtonVertical
                    )(
        Question()(TranslatedText("Race")),
        CodeListRef("CL_RACE")
    )
    meta << ItemDef("RACE_OTH", "RaceOther", DataType.Text, 20) \
           << Question() << TranslatedText("If Race Other, please specify")

    meta << ItemDef("DOB", "DateOfBirth", DataType.Date, 10,
                    control_type=ControlType.DateTime,
                    date_time_format="dd/mm/yyyy"