def loadStudyEvents(self):
        """Extract a list of Study Event domain objects according to ODM from metadata XML
        """
        studyEvents = []

        # Check if file path is setup
        if self.isFileLoaded:
            documentTree = ET.ElementTree(file=self.filename)

            # First obtain list of references (OIDs) to study events defined in ODM -> Study -> MetaDataVersion -> Protocol
            studyEventRefs = []

            for studyEventRef in documentTree.iterfind('.//odm:StudyEventRef', namespaces=nsmaps):
                studyEventRefs.append(studyEventRef.attrib['StudyEventOID'])

                # In case I need this information later
                # print studyEventRef.attrib['Mandatory']
                # print studyEventRef.attrib['OrderNumber']

            # Now for each study event reference find study event definition
            for eventRef in studyEventRefs:
                for element in documentTree.iterfind('.//odm:StudyEventDef[@OID="' + eventRef + '"]', namespaces=nsmaps):
                    studyEvent = StudyEventDefinition()

                    studyEvent.setOid(element.attrib['OID'])
                    studyEvent.setName(element.attrib['Name'])
                    studyEvent.setRepeating(element.attrib['Repeating'])
                    studyEvent.setType(element.attrib['Type'])

                    studyEvents.append(studyEvent)

        # Return resulting study event defintion elements
        return studyEvents
    def loadStudyEvents(self):
        """Extract a list of Study Event domain objects according to ODM from metadata XML
        """
        studyEvents = []

        # Check if file path is setup
        if (self.isFileLoaded):
            documentTree = ET.ElementTree(file=self.filename)

            # First obtain list of references (OIDs) to study events defined in ODM -> Study -> MetaDataVersion -> Protocol
            studyEventRefs = []

            for studyEventRef in documentTree.iterfind('.//odm:StudyEventRef', namespaces=nsmaps):
                studyEventRefs.append(studyEventRef.attrib['StudyEventOID'])

                # # In case I need this information later
                # print studyEventRef.attrib['Mandatory']
                # print studyEventRef.attrib['OrderNumber']

            # Now for each study event reference find study event definition
            for eventRef in studyEventRefs:
                for element in documentTree.iterfind('.//odm:StudyEventDef[@OID="' + eventRef + '"]', namespaces=nsmaps):
                    studyEvent = StudyEventDefinition()

                    studyEvent.setOid(element.attrib['OID'])
                    studyEvent.setName(element.attrib['Name'])
                    studyEvent.setRepeating(element.attrib['Repeating'])
                    studyEvent.setType(element.attrib['Type'])

                    studyEvents.append(studyEvent)

        # Return resulting study event defintion elements
        return studyEvents
    def loadEventsFromMetadata(self, metadata):
        """Extract a list of Study Event domain objects according to ODM from metadata XML
        """
        studyEvents = []

        # Check if file path is setup
        if (metadata):
            documentTree = ET.ElementTree((ET.fromstring(str(metadata))))

            # First obtain list of references (OIDs) to study events defined in ODM -> Study -> MetaDataVersion -> Protocol
            studyEventRefs = []

            for studyEventRef in documentTree.iterfind('.//odm:StudyEventRef', namespaces=nsmaps):
                studyEventRefs.append(studyEventRef.attrib['StudyEventOID'])
                # # In case I need this information later
                # print studyEventRef.attrib['Mandatory']
                # print studyEventRef.attrib['OrderNumber']

            # Now for each study event reference find study event definition
            for eventRef in studyEventRefs:
                for element in documentTree.iterfind('.//odm:StudyEventDef[@OID="' + eventRef + '"]', namespaces=nsmaps):
                    studyEvent = StudyEventDefinition()

                    studyEvent.setOid(element.attrib['OID'])
                    studyEvent.setName(element.attrib['Name'])
                    studyEvent.setRepeating(element.attrib['Repeating'] == "Yes")
                    studyEvent.setType(element.attrib['Type'])

                    for eventElement in element:
                        if (str(eventElement.tag)).strip() == "{http://www.openclinica.org/ns/odm_ext_v130/v3.1}EventDefinitionDetails":
                           for detailsElement in eventElement:
                                if (str(detailsElement.tag)).strip() == "{http://www.openclinica.org/ns/odm_ext_v130/v3.1}Description":
                                    studyEvent.description = detailsElement.text
                                elif (str(detailsElement.tag)).strip() == "{http://www.openclinica.org/ns/odm_ext_v130/v3.1}Category":
                                    studyEvent.category = detailsElement.text

                    studyEvents.append(studyEvent)

        # Return resulting study event defintion elements
        return studyEvents