示例#1
0
    def getStudyCasebookSubject(self, ocBaseUrl, studyOid, subjectId):
        """Get casebook of one subject
        SubjectId can be StudySubjectOID (SS_) or StudySubjectID (in new version of OC)
        """
        method = studyOid + "/" + subjectId + "/*/*"
        results = None

        r = self._ocRequest(ocBaseUrl, method)

        if r.status_code == 200:
            if "ClinicalData" in r.json():
                subjectData = r.json()["ClinicalData"]["SubjectData"]
                # Exactly one subject should be reported
                if type(subjectData) is dict:
                    subj = subjectData
                    subject = Subject()
                    subject.oid = subj["@SubjectKey"]
                    subject.studySubjectId = subj[
                        "@OpenClinica:StudySubjectID"]
                    if "@OpenClinica:UniqueIdentifier" in subj:
                        subject.uniqueIdentifier = subj[
                            "@OpenClinica:UniqueIdentifier"]
                    results.append(subject)

        return results
示例#2
0
    def getStudyCasebookSubjects(self, data, thread=None):
        """Get study casebook of all subjects
        """
        if data:
            ocBaseUrl = data[0]
            studyOid = data[1]

        method = studyOid + "/*/*/*"
        results = []

        r = self._ocRequest(ocBaseUrl, method)

        if r.status_code == 200:
            if "ClinicalData" in r.json():
                subjectData = r.json()["ClinicalData"]["SubjectData"]

                # Multiple subjects
                if type(subjectData) is list:
                    for subj in subjectData:
                        subject = Subject()
                        subject.oid = subj["@SubjectKey"]
                        subject.studySubjectId = subj[
                            "@OpenClinica:StudySubjectID"]
                        if "@OpenClinica:UniqueIdentifier" in subj:
                            subject.uniqueIdentifier = subj[
                                "@OpenClinica:UniqueIdentifier"]
                        results.append(subject)
                # Only one subject reported
                elif type(subjectData) is dict:
                    subj = subjectData
                    subject = Subject()
                    subject.oid = subj["@SubjectKey"]
                    subject.studySubjectId = subj[
                        "@OpenClinica:StudySubjectID"]
                    if "@OpenClinica:UniqueIdentifier" in subj:
                        subject.uniqueIdentifier = subj[
                            "@OpenClinica:UniqueIdentifier"]
                    results.append(subject)

        if thread:
            thread.emit(QtCore.SIGNAL("finished(QVariant)"), results)
            return None
        else:
            return results
    def getStudyCasebookSubject(self, ocBaseUrl, studyOid, subjectId):
        """Get casebook of one subject
        SubjectId can be StudySubjectOID (SS_) or StudySubjectID (in new version of OC)
        """
        method = studyOid + "/" + subjectId + "/*/*"
        results = None

        r = self._ocRequest(ocBaseUrl, method)

        if r.status_code == 200:
            if "ClinicalData" in r.json():
                subjectData = r.json()["ClinicalData"]["SubjectData"]
                # Exactly one subject should be reported
                if type(subjectData) is dict:
                    subj = subjectData
                    subject = Subject()
                    subject.oid = subj["@SubjectKey"]
                    subject.studySubjectId = subj["@OpenClinica:StudySubjectID"]
                    if "@OpenClinica:UniqueIdentifier" in subj:
                        subject.uniqueIdentifier = subj["@OpenClinica:UniqueIdentifier"]
                    results.append(subject)

        return results
    def __init__(self, parent=None):
        """Default constructor
        """
        QtGui.QDialog.__init__(self, parent)

        #------------------------------------------------------
        #-------------------- GUI -----------------------------
        self.width = 300
        self.height = 300
        self.setFixedSize(self.width, self.height)
        self.setWindowTitle("Create a new study subject")

        # Dialog layout root
        rootLayout = QtGui.QVBoxLayout(self)

        # Metadata field for mapping UI
        rootLayout.addWidget(self.__setupDialogFieldsUI())

        # Dialog buttons
        btnLayout = QtGui.QGridLayout()
        btnLayout.setSpacing(10)
        rootLayout.addLayout(btnLayout)

        self.btnOk = QtGui.QPushButton("Create")
        self.btnCancel = QtGui.QPushButton("Cancel")

        btnLayout.addWidget(self.btnOk, 1, 0)
        btnLayout.addWidget(self.btnCancel, 1, 1)

        #----------------------------------------------------------
        #----------------- Event handlers -------------------------

        self.btnOk.clicked.connect(self.handleOk)
        self.btnCancel.clicked.connect(self.handleCancel)

        #-----------------------------------------------------------
        #------------------ View Models ----------------------------
        self.newStudySubject = StudySubject()
        self.newStudySubject.subject = Subject()

        # Based on study subject id generation
        # if manual than specify
        # even if automatic it has to be empty string
        self.newStudySubject.label = ""

        # Based on metadata (can be optional)
        self.newStudySubject.subject.uniqueIdentifier = ""
示例#5
0
    def __init__(self, parent=None):
        """
        """
        QtGui.QDialog.__init__(self, parent)

        #------------------------------------------------------
        #-------------------- GUI -----------------------------
        self.width = 640
        self.height = 500
        self.setFixedSize(self.width, self.height)
        self.setWindowTitle("Create study subject dialog")

        # Dialog layout root
        rootLayout = QtGui.QVBoxLayout(self)

        # Metadata field for mapping UI
        rootLayout.addWidget(self.__setupDialogFieldsUI())

        # Dialog buttons
        btnLayout = QtGui.QGridLayout()
        btnLayout.setSpacing(10)
        rootLayout.addLayout(btnLayout)

        self.btnOk = QtGui.QPushButton("Create")
        self.btnCancel = QtGui.QPushButton("Cancel")

        btnLayout.addWidget(self.btnOk, 1, 0)
        btnLayout.addWidget(self.btnCancel, 1, 1)

        #----------------------------------------------------------
        #----------------- Event handlers -------------------------

        self.btnOk.clicked.connect(self.handleOk)
        self.btnCancel.clicked.connect(self.handleCancel)

        #-----------------------------------------------------------
        #------------------ View Models ----------------------------
        self.newStudySubject = StudySubject()
        self.newStudySubject.subject = Subject()

        #-----------------------------------------------------------
        #------------------ Services ----------------------------
        self.svcPseudonymisation = None
    def getStudyCasebookSubjects(self, data, thread=None):
        """Get study casebook subjects
        """
        if data:
            ocBaseUrl = data[0]
            studyOid = data[1]

        method = studyOid + "/*/*/*"
        results = []

        r = self._ocRequest(ocBaseUrl, method)

        if r.status_code == 200:
            if "ClinicalData" in r.json():
                subjectData = r.json()["ClinicalData"]["SubjectData"]

                # Multiple subjects
                if type(subjectData) is list:
                    for subj in subjectData:
                        subject = Subject()
                        subject.oid = subj["@SubjectKey"]
                        subject.studySubjectId = subj["@OpenClinica:StudySubjectID"]
                        if "@OpenClinica:UniqueIdentifier" in subj:
                            subject.uniqueIdentifier = subj["@OpenClinica:UniqueIdentifier"]
                        results.append(subject)
                # Only one subject reported
                elif type(subjectData) is dict:
                    subj = subjectData
                    subject = Subject()
                    subject.oid = subj["@SubjectKey"]
                    subject.studySubjectId = subj["@OpenClinica:StudySubjectID"]
                    if "@OpenClinica:UniqueIdentifier" in subj:
                        subject.uniqueIdentifier = subj["@OpenClinica:UniqueIdentifier"]
                    results.append(subject)

        if thread:
            thread.emit(QtCore.SIGNAL("finished(QVariant)"), results)
            return None
        else:
            return results
successfull = False
try:
    successfull, studies = ocWebServices.listAllStudies()
except:
    print "Cannot communicate with the server, no network connection or the server is not running."

if successfull:
    for study in studies:
        selectedStudy = study
        sucessfull, studyMetadata = ocWebServices.getStudyMetadata(
            selectedStudy)
        break

newStudySubject = StudySubject()
newStudySubject.subject = Subject()

# Based on study subject id generation
# if manual than specify
# even if automatic it has to be empty string
newStudySubject.label = ""

# Based on metadata (can be optional)
newStudySubject.subject.uniqueIdentifier = ""

# SecondaryId, BUG OC ignores secondary ID
#newStudySubject.secondaryId = ""

# Should depend on study configuration, BUG OC always requires gender
newStudySubject.subject.gender = "f"
#newStudySubject.subject.gender = "f"
示例#8
0
    def listAllByStudySite(self, study, studySite, metadata=None):
        """List all study subject assinged in specific study and site
        """
        result = ""

        params = SimpleXMLElement("""<?xml version="1.0" encoding="UTF-8"?>
            <listAllByStudyRequest>
            <bean:studyRef xmlns:bean="http://openclinica.org/ws/beans">
            <bean:identifier>""" + studySite.identifier + """</bean:identifier>
            </bean:studyRef>
            </listAllByStudyRequest>""")

        response = self.client.call('listAllByStudyRequest', params)

        documentTree = ET.ElementTree((ET.fromstring(str(response.as_xml()))))

        studySubjects = []

        # Locate Study subject data in XML file via XPath
        for studySubject in documentTree.iterfind('.//ns2:studySubject',
                                                  namespaces=nsmaps):
            label = ""
            secondaryLabel = ""
            enrollmentDate = ""
            uniqueIdentifier = ""
            gender = ""
            # Optional
            #dateOfBirth = str(studySubject.subject.dateOfBirth)
            events = []
            for element in studySubject:
                if (str(element.tag)
                    ).strip() == "{http://openclinica.org/ws/beans}label":
                    label = element.text
                elif (str(element.tag)).strip(
                ) == "{http://openclinica.org/ws/beans}secondaryLabel":
                    secondaryLabel = element.text
                elif (str(element.tag)).strip(
                ) == "{http://openclinica.org/ws/beans}enrollmentDate":
                    enrollmentDate = element.text

                if (str(element.tag)
                    ).strip() == "{http://openclinica.org/ws/beans}subject":
                    for subjectElement in element:
                        if (str(subjectElement.tag)).strip(
                        ) == "{http://openclinica.org/ws/beans}uniqueIdentifier":
                            uniqueIdentifier = subjectElement.text
                        elif (str(subjectElement.tag)).strip(
                        ) == "{http://openclinica.org/ws/beans}gender":
                            gender = subjectElement.text

                if (str(element.tag)
                    ).strip() == "{http://openclinica.org/ws/beans}events":
                    for event in element:
                        eventDefinitionOID = ""
                        location = ""
                        startDate = ""
                        startTime = ""
                        endDate = ""
                        endTime = ""

                        dateString = ""
                        timeString = ""
                        for eventElement in event:
                            if (str(eventElement.tag)).strip(
                            ) == "{http://openclinica.org/ws/beans}eventDefinitionOID":
                                eventDefinitionOID = eventElement.text
                            elif (str(eventElement.tag)).strip(
                            ) == "{http://openclinica.org/ws/beans}location":
                                location = eventElement.text
                            elif (str(eventElement.tag)).strip(
                            ) == "{http://openclinica.org/ws/beans}startDate":
                                dateString = eventElement.text
                            elif (str(eventElement.tag)).strip(
                            ) == "{http://openclinica.org/ws/beans}startTime":
                                timeString = eventElement.text

                        # Deal with both date an datetimes
                        if timeString == "":
                            format = "%Y-%m-%d"
                            startDate = datetime.strptime(dateString, format)
                        else:
                            # Carefull it uses 12/24 hour format
                            format12 = "%Y-%m-%d %I:%M:%S"
                            format24 = "%Y-%m-%d %H:%M:%S"

                            try:
                                startDate = datetime.strptime(
                                    dateString + " " + timeString, format12)
                            except ValueError:
                                startDate = datetime.strptime(
                                    dateString + " " + timeString, format24)

                        obtainedEvent = Event(eventDefinitionOID, startDate)
                        events.append(obtainedEvent)

            obtainedSubject = Subject(uniqueIdentifier, gender)
            obtainedStudySubject = StudySubject(label, secondaryLabel,
                                                enrollmentDate,
                                                obtainedSubject, events)

            studySubjects.append(obtainedStudySubject)

        # Enhance with information from metadata
        metadataEvents = self.loadEventsFromMetadata(metadata)

        for ss in studySubjects:
            for e in ss.events:
                for me in metadataEvents:
                    if e.eventDefinitionOID == me.oid:
                        e.name = me.name
                        e.description = me.description
                        e.isRepeating = me.repeating
                        e.eventType = me.type
                        e.category = me.category
                        e.mandatory = me.mandatory
                        e.orderNumber = me.orderNumber

        result = str(response.result)
        return studySubjects