How to use the rwslib.builders.common.TransactionalElement 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 / clinicaldata.py View on Github external
def __lshift__(self, other):
        """Override << operator"""
        if not isinstance(other, (StudyEventData, AuditRecord, Annotation, Signature, SiteRef)):
            raise ValueError("SubjectData object can only receive StudyEventData, AuditRecord, "
                             "Annotation or Signature object")

        self.set_list_attribute(other, Annotation, 'annotations')
        self.set_list_attribute(other, StudyEventData, 'study_events')
        self.set_single_attribute(other, AuditRecord, 'audit_record')
        self.set_single_attribute(other, Signature, 'signature')
        self.set_single_attribute(other, SiteRef, 'siteref')

        return other


class StudyEventData(TransactionalElement, LastUpdateMixin, MilestoneMixin):
    """Models the ODM StudyEventData object"""
    ALLOWED_TRANSACTION_TYPES = ['Insert', 'Update', 'Remove', 'Context']

    def __init__(self, study_event_oid, transaction_type="Update", study_event_repeat_key=None):
        """
        :param str study_event_oid: :class:`StudyEvent` OID
        :param str transaction_type: Transaction Type for Data (one of **Insert**, **Update**, *Remove*, **Context**)
        :param int study_event_repeat_key: :attr:`StudyEventRepeatKey` for StudyEventData
        """
        super(self.__class__, self).__init__(transaction_type)
        self.study_event_oid = study_event_oid
        self.study_event_repeat_key = study_event_repeat_key
        #: :class:`FormData` part of Study Event Data
        self.forms = []
        #: :class:`Annotation` for Study Event Data  - *Not Supported by Rave*
        self.annotations = []
github mdsol / rwslib / rwslib / builders / clinicaldata.py View on Github external
def __lshift__(self, other):
        """Override << operator"""
        if not isinstance(other, (ItemData, Annotation, Signature)):
            raise ValueError("ItemGroupData object can only receive ItemData, Signature or Annotation objects")

        self.set_list_attribute(other, Annotation, 'annotations')
        self.set_single_attribute(other, Signature, 'signature')
        if isinstance(other, ItemData):
            if other.itemoid in self.items:
                raise ValueError("ItemGroupData object with that itemoid is already in the ItemGroupData object")
            self.items[other.itemoid] = other
        return other


class ItemData(TransactionalElement, LastUpdateMixin, MilestoneMixin):
    """Models the ODM ItemData object"""
    ALLOWED_TRANSACTION_TYPES = ['Insert', 'Update', 'Upsert', 'Context', 'Remove']

    def __init__(self, itemoid, value, specify_value=None, transaction_type=None, lock=None, freeze=None, verify=None):
        """
        :param str itemoid: OID for the matching :class:`ItemDef`
        :param str value: Value for the the ItemData
        :param str specify_value: 'If other, specify' value - *Rave specific attribute*
        :param str transaction_type: Transaction type for the data
        :param bool lock: Lock the DataPoint? - *Rave specific attribute*
        :param bool freeze: Freeze the DataPoint? - *Rave specific attribute*
        :param bool verify: Verify the DataPoint? - *Rave specific attribute*
        """
        super(self.__class__, self).__init__(transaction_type)
        self.itemoid = itemoid
        self.value = value
github mdsol / rwslib / rwslib / builders / clinicaldata.py View on Github external
builder.end("FormData")

    def __lshift__(self, other):
        """Override << operator"""
        if not isinstance(other, (Signature, ItemGroupData, Annotation)):
            raise ValueError(
                "FormData object can only receive ItemGroupData, Signature or Annotation objects (not '{}')".format(
                    other))
        self.set_list_attribute(other, ItemGroupData, 'itemgroups')
        self.set_list_attribute(other, Annotation, 'annotations')
        self.set_single_attribute(other, Signature, 'signature')
        return other


class ItemGroupData(TransactionalElement, LastUpdateMixin, MilestoneMixin):
    """
    Models the ODM ItemGroupData object.

    .. note:: No name for the ItemGroupData element is required. This is built automatically by the form.
    """
    ALLOWED_TRANSACTION_TYPES = ['Insert', 'Update', 'Upsert', 'Context']

    def __init__(self, itemgroupoid=None, transaction_type=None, item_group_repeat_key=None,
                 whole_item_group=False, annotations=None):
        """
        :param str transaction_type: TransactionType for the ItemGroupData
        :param int item_group_repeat_key: RepeatKey for the ItemGroupData
        :param bool whole_item_group: Is this the entire ItemGroupData, or just parts? - *Rave specific attribute*
        :param annotations: Annotation for the ItemGroup - *Not supported by Rave*
        :type annotations: list(Annotation) or Annotation
        """
github mdsol / rwslib / rwslib / builders / clinicaldata.py View on Github external
subject.build(builder)
        # Add the Annotations
        if self.annotations is not None:
            self.annotations.build(builder)
        builder.end("ClinicalData")

    def __lshift__(self, other):
        """Override << operator"""
        if not isinstance(other, (SubjectData, Annotations)):
            raise ValueError("ClinicalData object can only receive SubjectData or Annotations object")
        self.set_list_attribute(other, SubjectData, 'subject_data')
        self.set_single_attribute(other, Annotations, 'annotations')
        return other


class SubjectData(TransactionalElement, LastUpdateMixin, MilestoneMixin):
    """Models the ODM SubjectData and ODM SiteRef objects"""
    ALLOWED_TRANSACTION_TYPES = ['Insert', 'Update', 'Upsert']

    def __init__(self, site_location_oid, subject_key, subject_key_type="SubjectName", transaction_type="Update"):
        """
        :param str site_location_oid: :class:`SiteLocation` OID
        :param str subject_key: Value for SubjectKey
        :param str subject_key_type: Specifier as to the type of SubjectKey (either **SubjectName** or **SubjectUUID**)
        :param str transaction_type: Transaction Type for Data (one of **Insert**, **Update**, **Upsert**)
        """
        super(self.__class__, self).__init__(transaction_type)
        self.sitelocationoid = site_location_oid
        self.subject_key = subject_key
        self.subject_key_type = subject_key_type
        #: collection of :class:`StudyEventData`
        self.study_events = []
github mdsol / rwslib / rwslib / builders / clinicaldata.py View on Github external
for annotation in self.annotations:
            annotation.build(builder)

        builder.end("StudyEventData")

    def __lshift__(self, other):
        """Override << operator"""
        if not isinstance(other, (FormData, Annotation, Signature)):
            raise ValueError("StudyEventData object can only receive FormData, Signature or Annotation objects")
        self.set_list_attribute(other, FormData, 'forms')
        self.set_single_attribute(other, Signature, 'signature')
        self.set_list_attribute(other, Annotation, 'annotations')
        return other


class FormData(TransactionalElement, LastUpdateMixin, MilestoneMixin):
    """Models the ODM FormData object"""
    ALLOWED_TRANSACTION_TYPES = ['Insert', 'Update']

    def __init__(self, formoid, transaction_type=None, form_repeat_key=None):
        """
        :param str formoid: :class:`FormDef` OID
        :param str transaction_type: Transaction Type for Data (one of **Insert**, **Update**)
        :param str form_repeat_key: Repeat Key for FormData
        """
        super(FormData, self).__init__(transaction_type)
        self.formoid = formoid
        self.form_repeat_key = form_repeat_key
        self.itemgroups = []
        #: :class:`Signature` for FormData
        self.signature = None  # type: Signature
        #: Collection of :class:`Annotation` for FormData - *Not supported by Rave*
github mdsol / rwslib / rwslib / builders / clinicaldata.py View on Github external
builder.end("Signature")

    def __lshift__(self, other):
        if not isinstance(other, (UserRef, LocationRef, SignatureRef, DateTimeStamp,)):
            raise ValueError("Signature cannot accept a child element of type %s" % other.__class__.__name__)

        # Order is important, apparently
        self.set_single_attribute(other, UserRef, 'user_ref')
        self.set_single_attribute(other, LocationRef, 'location_ref')
        self.set_single_attribute(other, SignatureRef, 'signature_ref')
        self.set_single_attribute(other, DateTimeStamp, 'date_time_stamp')
        return other


class Annotation(TransactionalElement):
    """
    A general note about clinical data.
    If an annotation has both a comment and flags, the flags should be related to the comment.

    .. note:: Annotation is not supported by Medidata Rave
    """
    ALLOWED_TRANSACTION_TYPES = ["Insert", "Update", "Remove", "Upsert", "Context"]

    def __init__(self, annotation_id=None, seqnum=1,
                 flags=None, comment=None,
                 transaction_type=None):
        """
        :param id: ID for this Annotation (required if contained within an Annotations element)
        :type id: str or None
        :param int seqnum: :attr:`SeqNum` for Annotation
        :param flags: one or more :class:`Flag` for the Annotation
github mdsol / rwslib / rwslib / builders / clinicaldata.py View on Github external
builder.end("AuditRecord")

    def __lshift__(self, other):
        if not isinstance(other, (UserRef, LocationRef, DateTimeStamp, ReasonForChange, SourceID)):
            raise ValueError("AuditRecord cannot accept a child element of type %s" % other.__class__.__name__)

        # Order is important, apparently
        self.set_single_attribute(other, UserRef, 'user_ref')
        self.set_single_attribute(other, LocationRef, 'location_ref')
        self.set_single_attribute(other, DateTimeStamp, 'date_time_stamp')
        self.set_single_attribute(other, ReasonForChange, 'reason_for_change')
        self.set_single_attribute(other, SourceID, 'source_id')
        return other


class MdsolProtocolDeviation(TransactionalElement):
    """
    Extension for Protocol Deviations in Rave

    .. note::
        * This is a Medidata Rave Specific Extension
        * This primarily exists as a mechanism for use by the Clinical Audit Record Service, but it is useful to define for the builders

    """
    ALLOWED_TRANSACTION_TYPES = ["Insert"]

    def __init__(self, value, status, repeat_key=1, code=None, klass=None, transaction_type=None):
        """
        :param str value: Value for the Protocol Deviation 
        :param rwslib.builder_constants.ProtocolDeviationStatus status: 
        :param int repeat_key: RepeatKey for the Protocol Deviation
        :param basestring code: Protocol Deviation Code