def getBarcodeStats(self): """ Simple project / subject / barcode stats """ self.getGUIFieldValue() if self.stats_type == 'Project': proj_stats = self.redcapExec.getProjectStats() curTime = datetime.now() cur_date = curTime.strftime('%Y-%m-%d %H:%M') self.plain_console.appendPlainText("\n\n%s\nProject Stats:\n%s" % (str(cur_date), proj_stats)) elif self.stats_type == 'Subject': if self.subjectId == '' or self.subjectId == None: QMessageBox.about( self, "WARNING", "Subject id is empty. Get stats for subject %s failed." % str(self.subjectId)) return self.getSubjectType() # --> force to select correct subject type if self.studyType == '' or self.studyType == None: QMessageBox.about( self, "WARNING", "Study type is empty. Get stats for subject %s failed." % str(self.subjectId)) return # a hacking here because we don't care if the subject contains extra frozen id or not. barcodeExec = BarcodeGenerator(self.subjectId, self.studyType) barcodeExec.execute() tmp_barcode_list = barcodeExec.get_barcode_list(self.custom_option) subj_stats = self.redcapExec.getSubjectStats(tmp_barcode_list) curTime = datetime.now() cur_date = curTime.strftime('%Y-%m-%d %H:%M') self.plain_console.appendPlainText( "\n\n%s\nSubject %s Stats:\n%s" % (str(cur_date), self.subjectId, subj_stats)) elif self.stats_type == 'Barcode': if self.barcode_id is '' or self.barcode_id is None: QMessageBox.about( self, "WARNING", "Barcode id is empty. Set scan status failed. \n\n Please fill up barcode id box" ) return barcode_stats = self.redcapExec.getBarcodeStats(self.barcode_id) curTime = datetime.now() cur_date = curTime.strftime('%Y-%m-%d %H:%M') self.plain_console.appendPlainText( "\n\n%s\nBarcode %s Stats is stored in :\n%s" % (str(cur_date), self.barcode_id, barcode_stats)) self.plain_console.repaint() self.plain_console.moveCursor(QTextCursor.End)
def genPrintNewPack(self): """ Generate and print new full pack of barcodes """ self.getGUIFieldValue() if self.subjectId == '' or self.subjectId == None: QMessageBox.about( self, "WARNING", "Subject id is empty. Generate / Print new pack for subject %s failed." % str(self.subjectId)) return if len(self.subjectId) != 3: QMessageBox.about( self, "WARNING", "Subject id should be three digit. Please double-check") return if self.studyType == '' or self.studyType == None: QMessageBox.about( self, "WARNING", "Study type is empty. Generate / Print new pack for subject %s failed." % str(self.subjectId)) return if self.processed_by == '' or self.processed_by == None: QMessageBox.about(self, "WARNING", "Please select current user.") return if self.custom_option == '' or self.custom_option == None: QMessageBox.about(self, "WARNING", "Please select custom option for printing.") return ###add constraint to restrict one patient can only be one type curSubj = self.redcapExec.getInputPatient() df = pd.DataFrame.from_dict(curSubj) record = df.loc[df['record_id_dem_endo'] == str(int(self.subjectId))] if len(record) is 0 or None: QMessageBox.about( self, "WARNING", "--- Please create subject %s form first.\nPlease double check the Id in Redcap entry.\nThe Id should be in numeric format (i.e., 17, 20, 99), \nnot in 3-digit format (i.e., 017, 020, 099)" % str(self.subjectId)) return studyType_redcap = record.get('redcap_event_name').values if len(studyType_redcap) > 1: QMessageBox.about( self, "WARNING", "--- Please check subject %s Redcap data entry.\nOnly one category per patient is allowed.\nIf there is only one catogory has been selected" % str(self.subjectId)) return #"CD_ENDO", "CTL_ENDO", "CD_Surgery","CTL_Surgery" if studyType_redcap == 'cd_arm_1': studyType_checker = 'CD_ENDO' elif studyType_redcap == 'control_arm_1': studyType_checker = 'CTL_ENDO' elif studyType_redcap == 'cd_arm_2': studyType_checker = 'CD_Surgery' elif studyType_redcap == 'control_arm_2': studyType_checker = 'CTL_Surgery' if studyType_checker != self.studyType: print(studyType_redcap) QMessageBox.about( self, "WARNING", "Study type for subject %s does not match. Should it be %s?" % (str(self.subjectId), str(studyType_checker))) return # all set, ready to generate barcode pack barcodeExec = BarcodeGenerator(self.subjectId, self.studyType) barcodeExec.execute() #can optimize - done? nextAvailActionId = self.redcapExec.getNextAvailActionId() # new feature 12/19/2019 tmp_barcode_list = barcodeExec.get_barcode_list( self.custom_option) # More constraint before Christmas... #set generate action for tmp_barcode_id in tmp_barcode_list: if tmp_barcode_id == '': # no need to print continue ean8_code = barcodeExec.recordId_to_ean8(tmp_barcode_id) # generate ean8 code to make sure it matches our criteria if ean8_code is None: QMessageBox.about( self, "WARNING", "Something wrong with barcode id %s?" % (tmp_barcode_id)) return self.printLabel(tmp_barcode_id, ean8_code) # add barcode ean8 code self.redcapExec.setPrintedAction(nextAvailActionId, tmp_barcode_id, self.studyType, self.processed_by, self.action_comment, ean8_code, self.custom_option) nextAvailActionId += 1 bool_update_redcap_sophie = self.redcapExec.update_REDCAP_SOPHIE( self.studyType, str(int(self.subjectId)), tmp_barcode_list, self.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\nGenerate new pack for subject %s DONE!\nCustom option:%s\n Printing may takes time, please be patient.\nTotal barcodes to print: %s" % (str(cur_date), str(self.subjectId), str( self.custom_option), str(len(tmp_barcode_list)))) self.cb_option_type.setCurrentIndex(0) self.plain_console.repaint() self.plain_console.moveCursor(QTextCursor.End)