Example #1
0
    def set_scanned_id(self, scanned_id):
        """
        Convert ean8 id to real barcode id
        """
        barcodeExec = BarcodeGenerator()

        tmp_barcode_id = ''
        # hacking because location app does not have self.subject field
        if scanned_id[0:3] == 'GCA':
            # in case users manaully type the barcode. No need ean8 conversion.
            self.barcode_id = scanned_id  # self.subject is not set in barcode_generator...
        else:
            if barcodeExec.is_valid(str(scanned_id)) is False:
                QtWidgets.QMessageBox.about(
                    Form, "WARNING",
                    "Barcode is not valid(1). Please contact to administrator")
                self.plain_console.repaint()
                return False

            tmp_barcode_id = barcodeExec.ean8_to_recordId(scanned_id)
            if tmp_barcode_id is None:
                QtWidgets.QMessageBox.about(
                    Form, "WARNING",
                    "Barcode is not valid(2). Please contact to administrator")
                self.plain_console.repaint()
                return False

            # set GUI
            self.barcode_id = tmp_barcode_id

        # set GUI
        self.textbox_barcode_id.setText(self.barcode_id)
        self.subjectId = self.barcode_id[3:6]
        tmp_custom_option = self.redcapExec.getSubjectLastestCustomOption(
            self.barcode_id, self.subjectId)
        if tmp_custom_option is False:
            QMessageBox.about(
                self, "WARNING",
                "Barcode %s is not found \n\n please generate barcode first" %
                str(self.barcode_id))
            return

        tmp_studyType = scanned_id[0:1]

        if tmp_studyType == '1':
            self.cb_study_type.setCurrentIndex(1)
        elif tmp_studyType == '2':
            self.cb_study_type.setCurrentIndex(2)
        elif tmp_studyType == '3':
            self.cb_study_type.setCurrentIndex(3)
        elif tmp_studyType == '4':
            self.cb_study_type.setCurrentIndex(4)
        # add a new barcode actoin record
        nextAvailActionId = self.redcapExec.getNextAvailActionId()
        self.redcapExec.setScannedAction(nextAvailActionId, self.barcode_id,
                                         self.studyType, self.processed_by,
                                         self.action_comment, scanned_id,
                                         tmp_custom_option)
        self.plain_comment.clear()
        curTime = datetime.now()
        cur_date = curTime.strftime('%Y-%m-%d %H:%M')
        self.plain_console.appendPlainText(
            "\n\n%s\nSet barcode %s scanned status DONE!" %
            (str(cur_date), str(self.barcode_id)))
        self.plain_console.repaint()
        self.plain_console.moveCursor(QTextCursor.End)
Example #2
0
    def set_scanned_id(self, scanned_id):
        """
        Convert ean8 id to real barcode id
        """

        barcodeExec = BarcodeGenerator()
        # hacking in case the input code is GCA blabla blabla
        #
        tmp_barcode_id = ''
        # hacking because location app does not have self.subject field
        if scanned_id[0:3] == 'GCA':
            self.barcode_id = self.stringUpperLowerHack(scanned_id)
        else:
            if barcodeExec.is_valid(str(scanned_id)) is False:
                QtWidgets.QMessageBox.about(
                    Form, "WARNING",
                    "Barcode is not valid(1). Please contact to administrator")
                #self.plain_console.repaint()
                self.plain_console_repaint()
                return False

            tmp_barcode_id = barcodeExec.ean8_to_recordId(scanned_id)
            if tmp_barcode_id is None:
                QtWidgets.QMessageBox.about(
                    Form, "WARNING",
                    "Barcode is not valid(2). Please contact to administrator")
                #self.plain_console.repaint()
                self.plain_console_repaint()
                return False

            # set GUI
            self.barcode_id = tmp_barcode_id

        self.subjectId = self.barcode_id[3:6]
        self.redcapExec.getBarcodeSubset_StudyType_Action_CustomOption(
        )  # for one time query...
        tmp_study_type, tmp_action_type, tmp_custom_option = self.redcapExec.getSubjectLastestActionAndCustomOption(
            self.barcode_id, self.subjectId)
        if tmp_custom_option is False:
            QtWidgets.QMessageBox.about(
                Form, "WARNING",
                "Barcode %s is not found \n\n " % str(self.barcode_id))
            return False

        # initialize barcodeExec class variables
        barcodeExec._subject_id = self.subjectId
        barcodeExec._studyType = tmp_study_type
        # self.textbox_barcode_id.setText(self.barcode_id)

        self.fillScannedBarcodeToTable(self.barcode_id)

        nextAvailActionId = self.redcapExec.getNextAvailActionId()

        # once we confirmed the input id exists, we can safely convert the id to ean8 code.
        # This is only for manually input...

        if scanned_id[0:3] == 'GCA':
            scanned_id = barcodeExec.recordId_to_ean8(self.barcode_id)

        self.redcapExec.setScannedAction(nextAvailActionId, self.barcode_id,
                                         tmp_study_type, self.processed_by,
                                         self.plain_comment.toPlainText(),
                                         scanned_id, tmp_custom_option)

        curTime = datetime.now()
        curTime = datetime.now()
        cur_date = curTime.strftime('%Y-%m-%d %H:%M')
        self.plain_console.append(
            "\n\n%s\nSet barcode %s scanned status DONE!" %
            (str(cur_date), str(self.barcode_id)))
        self.plain_console_repaint()

        return True