加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
school_workflow.py 30.47 KB
一键复制 编辑 原始数据 按行查看 历史
陈敏华 提交于 2021-04-16 14:02 . 1.增加codeisland的校筛数据导入
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
#! /usr/bin/env python3
# -*- coding: UTF-8 -*-
# Author: Bary Chen
from copy import deepcopy
from PyQt5 import QtCore, QtGui, QtWidgets
from tools import qt, tasks
from tools.env_paras import DATABASE
from widgets.workflow_UI import Ui_Form
class StudyStatus(QtWidgets.QWidget, Ui_Form):
fr8900_not_available = QtCore.pyqtSignal()
fr8900_is_available = QtCore.pyqtSignal()
vat300_not_available = QtCore.pyqtSignal()
vat300_is_available = QtCore.pyqtSignal()
dialog_closed = QtCore.pyqtSignal()
ready = QtCore.pyqtSignal(list, dict)
def __init__(self, parent=None, student=None, school=None, province=None, city=None, county=None):
super(StudyStatus, self).__init__(parent)
self.setupUi(self)
self.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.WindowCloseButtonHint)
self.setWindowModality(QtCore.Qt.ApplicationModal)
self.setWindowTitle(self.tr('Study Status'))
self.resize(480, 580) # 1920*1080分辨率下此size刚刚好
self.school = school
self.student = student
self.province = province
self.city = city
self.county = county
if parent:
self.logger = self.parent().logger
self.mutex = self.parent().mutex
else:
return
self.local_server_port_for_visual_chart = self.parent().config['SchoolMode']['LocalServerPortForVisualChart']
self.vat300_server_port = self.parent().config['SchoolMode']['VAT300ServerPort']
self.pushButton_MRT_Start.setIcon(qt.newIcon('confirm'))
self.pushButton_MRT_Start.clicked.connect(self.start_mrt)
self.pushButton_Optometry_Data.clicked.connect(self.collect_optometry_data)
self.checkBox_Optometry_Required.stateChanged.connect(lambda: self.pushButton_Optometry_Data.setEnabled(
self.checkBox_Optometry_Required.isChecked()))
self.checkBox_Visual_Acuity_Required.stateChanged.connect(
lambda: self.pushButton_Acquire_Uncorrected_Data.setEnabled(
self.checkBox_Visual_Acuity_Required.isChecked()))
self.checkBox_Visual_Acuity_Required.stateChanged.connect(
lambda: self.pushButton_Acquire_Corrected_Data.setEnabled(
self.checkBox_Visual_Acuity_Required.isChecked()))
self.pushButton_Acquire_Uncorrected_Data.clicked.connect(self.acquire_vision_data_manually)
self.pushButton_Acquire_Corrected_Data.clicked.connect(self.acquire_vision_data_manually)
self.tableWidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.tableWidget.verticalHeader().setVisible(False)
self.tableWidget.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
self.tableWidget.itemChanged.connect(self.update_corrected_vision)
# staff
self.ser_fr8900 = None # 初始化验光仪串口对象
self.vat300_ip = '' # vat 300视力表ip地址
self.current_vision = {}
QtCore.QTimer.singleShot(200, self.connect_fr8900)
self.current_vision_query_mode = 0 # 手动查询视力表,0为查询裸眼视力,1为查询矫正视力
# 查询orthanc最近的检查记录, 暂时不用查询
# self.orthanc_query_thread = tasks.GetPatientsInOrthanc(self, self.parent().config['orthanc']['IP'],
# self.parent().config['orthanc']['Port'],
# self.parent().config['orthanc']['QueryInterval'],
# query_all=False)
# self.orthanc_query_thread.queried.connect(self.orthanc_queried)
# self.orthanc_query_thread.query_failed.connect(
# lambda msg: QtWidgets.QMessageBox.critical(self, self.tr('Error'),
# msg, QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok))
# self.orthanc_query_timer = QtCore.QTimer()
# self.orthanc_query_timer.timeout.connect(lambda: self.orthanc_query_thread.start())
# self.orthanc_query_timer.start(self.parent().config['orthanc']['QueryInterval'] * 1000)
# 验光仪连接线程
self.refractometer_finder_thread = tasks.ConnectFR8900(self, timeout=3)
self.refractometer_finder_thread.fr8900_is_available.connect(lambda: self.fr8900_is_available.emit())
# 视力表连接线程
self.vision_chart_finder_thread = tasks.ConnectVAT300(self, device_server_port=self.vat300_server_port)
self.vision_chart_finder_thread.device_is_available.connect(lambda: self.vat300_is_available.emit())
self.vision_chart_finder_thread.device_is_available.connect(self.start_vision_chart_query)
self.vision_chart_finder_thread.device_not_available.connect(lambda: self.vat300_not_available.emit())
self.vision_chart_finder_thread.device_not_available.connect(self.start_searching_vision_chart)
self.vision_chart_timer = QtCore.QTimer()
self.vision_chart_timer.timeout.connect(self.deal_vision_data)
self.vision_chart_query_thread = tasks.VAT300Query(self, device_server_port=self.vat300_server_port)
self.vision_chart_query_thread.queried.connect(self.vision_data_queried)
self.vision_chart_query_thread.failed.connect(lambda: self.vat300_not_available.emit())
self.vision_chart_query_thread.failed.connect(self.start_searching_vision_chart)
self.vision_chart_query_thread.error.connect(
lambda msg: QtWidgets.QMessageBox.critical(self, self.tr('Error'), msg,
QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok))
QtCore.QTimer.singleShot(300, self.start_searching_vision_chart)
def start_searching_vision_chart(self):
# 丢失连接后同时停止查询线程
if not self.parent().config['SchoolMode']['VisualChartRequired']:
return
if self.vision_chart_query_thread.isRunning():
self.vision_chart_query_thread.terminate()
self.vision_chart_query_thread.wait(1000)
if self.vision_chart_finder_thread.isRunning():
self.vision_chart_finder_thread.terminate()
self.vision_chart_finder_thread.wait(100)
self.logger.info('Start identifying Vision Chart')
self.vision_chart_finder_thread.start()
def start_vision_chart_service(self, local_ip):
self.parent().label_Local_IP.setText(
self.tr('Vision Service URL: http://%s:%s') % (local_ip, str(self.local_server_port_for_visual_chart)))
# 视力表后台服务
self.vision_chart_service_thread = tasks.VAT300Service(self, local_ip, self.local_server_port_for_visual_chart)
self.vision_chart_service_thread.queried.connect(self.vision_data_queried)
self.vision_chart_service_thread.error.connect(
lambda msg: QtWidgets.QMessageBox.critical(self, self.tr('Error'), msg,
QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok))
self.vision_chart_service_thread.start()
def start_vision_chart_query(self, vat_ip):
self.vision_chart_query_thread.device_ip = vat_ip
if self.vision_chart_query_thread.isRunning():
self.vision_chart_query_thread.terminate()
self.vision_chart_query_thread.wait(1000)
# self.vision_chart_query_thread.start() # 主动查询变为手动查询
def initialize_table(self):
self.tableWidget.setRowCount(0)
self.tableWidget.setColumnCount(0)
column_labels = ['', self.tr('OD'), self.tr('OS')]
row_labels = (
self.tr('Pupillary Distance(mm)'), self.tr('Uncorrected Vision'), self.tr('Corrected Vision(Option)'),
self.tr('Spherical Diopter(D)'), self.tr('Astigmatism Degree(D)'),
self.tr('Astigmatism Axial(%s)') % '°', self.tr('Spherical Equivalent(D)'))
self.tableWidget.setColumnCount(len(column_labels))
self.tableWidget.setRowCount(len(row_labels))
bold_font = QtGui.QFont()
bold_font.setBold(True)
for col, head_txt in enumerate(column_labels):
head_item = QtWidgets.QTableWidgetItem(head_txt)
head_item.setTextAlignment(QtCore.Qt.AlignCenter)
head_item.setFont(bold_font)
self.tableWidget.setHorizontalHeaderItem(col, head_item)
for row in range(self.tableWidget.rowCount()):
cell_item = QtWidgets.QTableWidgetItem(row_labels[row])
cell_item.setTextAlignment(QtCore.Qt.AlignCenter)
cell_item.setFlags(QtCore.Qt.ItemIsEditable)
cell_item.setFont(bold_font)
self.tableWidget.setItem(row, 0, cell_item)
info = self._get_current_student_all_data()
if not info:
return
unc_od, nc_od, unc_os, nc_os, pd, s_od, c_od, a_od, se_od, s_os, c_os, a_os, se_os = info[12:25]
optometry = {1: [pd, unc_od, nc_od, s_od, c_od, a_od, se_od], 2: [pd, unc_os, nc_os, s_os, c_os, a_os, se_os]}
for row in range(self.tableWidget.rowCount()):
for col in (1, 2):
txt = optometry[col][row]
if txt:
cell_item = QtWidgets.QTableWidgetItem(txt)
else:
cell_item = QtWidgets.QTableWidgetItem()
cell_item.setTextAlignment(QtCore.Qt.AlignCenter)
self.tableWidget.setItem(row, col, cell_item)
self.tableWidget.setSpan(0, 1, 1, 2) # 合并瞳距的单元格
def fill_student_info(self):
if self.student:
student_id = self.student.get('id_card', '')
if qt.isChineseCitizenID(student_id):
student_id = student_id[:3] + '*' * 12 + student_id[-3:]
self.lineEdit_Student_Id.setText(student_id)
student_name = self.student.get('name', '')
self.lineEdit_Student_Name.setText(student_name)
student_gender = self.student.get('gender', '')
self.lineEdit_Student_Gender.setText(student_gender)
student_birthdate = self.student.get('birthday', '')
self.lineEdit_Student_Birthdate.setText(student_birthdate)
else:
return
self.checkBox_Optometry_Required.setChecked(self.parent().config['SchoolMode']['RefractometerRequired'])
self.checkBox_Optometry_Required.setEnabled(self.parent().config['SchoolMode']['RefractometerRequired'])
self.checkBox_Visual_Acuity_Required.setChecked(self.parent().config['SchoolMode']['VisualChartRequired'])
self.checkBox_Visual_Acuity_Required.setEnabled(self.parent().config['SchoolMode']['VisualChartRequired'])
QtCore.QTimer.singleShot(0, self.update_btn_indicator)
def update_btn_indicator(self):
# if self.has_optometry_obtained(update_btn=True):
# self.pushButton_Optometry_Data.setIcon(qt.newIcon('checked'))
# self.pushButton_Optometry_Data.setText(self.tr('Acquire again'))
# else:
# self.pushButton_Optometry_Data.setIcon(qt.newIcon('update'))
# self.pushButton_Optometry_Data.setText(self.tr('Acquire Data'))
info = self._get_current_student_all_data()
if not info:
return
optometry = info[17:25] # 不考虑pd
uncorrected_vision = (info[12], info[14])
corrected_vision = (info[13], info[15])
if optometry.count(None) > 4: # 无验光仪数据
self.pushButton_Optometry_Data.setIcon(qt.newIcon('update'))
self.pushButton_Optometry_Data.setText(self.tr('Acquire data'))
else:
self.pushButton_Optometry_Data.setIcon(qt.newIcon('checked'))
self.pushButton_Optometry_Data.setText(self.tr('Acquire again'))
if uncorrected_vision.count(None) == 2: # 无裸眼视力数据
self.pushButton_Acquire_Uncorrected_Data.setIcon(qt.newIcon('update'))
self.pushButton_Acquire_Uncorrected_Data.setText(self.tr('Acquire uncorrected vision data'))
else:
self.pushButton_Acquire_Uncorrected_Data.setIcon(qt.newIcon('checked'))
self.pushButton_Acquire_Uncorrected_Data.setText(self.tr('Acquire Uncorrected vision data again'))
if corrected_vision.count(None) == 2: # 无矫正视力数据
self.pushButton_Acquire_Corrected_Data.setIcon(qt.newIcon('update'))
self.pushButton_Acquire_Corrected_Data.setText(self.tr('Acquire corrected vision data'))
else:
self.pushButton_Acquire_Corrected_Data.setIcon(qt.newIcon('checked'))
self.pushButton_Acquire_Corrected_Data.setText(self.tr('Acquire corrected vision data again'))
def connect_fr8900(self):
if not self.parent().config['SchoolMode']['RefractometerRequired']:
return
self.logger.info('Start connecting FR8900')
if self.ser_fr8900:
self.ser_fr8900.close()
self.ser_fr8900 = None
if not self.refractometer_finder_thread.isRunning():
self.refractometer_finder_thread.ser_fr8900 = None
self.refractometer_finder_thread.start()
def collect_optometry_data(self):
if not self.ser_fr8900:
QtWidgets.QMessageBox.critical(self, self.tr('Error'),
self.tr('FR8900 is not connected.\n'
'Please check cable connection and make sure FR8900 is on.'),
QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
return
thread = tasks.QueryDataFromFR8900(self)
thread.error.connect(lambda msg:
QtWidgets.QMessageBox.critical(self, self.tr('Error'),
self.tr('Can not query data from FR8900:\n%s\n\n'
'Please check cable connection and make sure '
'FR8900 is on.') % msg,
QtWidgets.QMessageBox.Ok,
QtWidgets.QMessageBox.Ok))
thread.error.connect(lambda: self.fr8900_not_available.emit())
thread.error.connect(self.connect_fr8900)
thread.finished.connect(thread.deleteLater)
thread.queried.connect(self.optometry_data_queried)
thread.start()
def update_info(self, data: (tuple, list), head_of_update: int):
info = self._get_current_student_all_data()
if info:
idx = head_of_update # 数据库内第16列开始为验光数据, 第12列开始为视力表数据
for value in data:
if value is not None:
info[idx] = str(value)
idx += 1
self.logger.info(f'Update optometry data of {info[1]}')
else:
student_id = self.student.get('ID', None)
if not student_id:
self.logger.critical('No student ID')
return
name = self.student.get('Name', None)
if not name:
self.logger.critical('No student name')
return
gender = self.student.get('Gender', None)
if not gender:
self.logger.critical('No student gender')
return
birthday = self.student.get('Birthday', None)
if not birthday or not isinstance(birthday, (list, tuple)):
self.logger.critical('No student birthdate')
return
birthday = QtCore.QDate(*birthday).toString('yyyy/MM/dd')
grade = self.student.get('Grade', None)
if not grade:
self.logger.critical('No student grade')
return
class_name = self.student.get('Class', None)
if not class_name:
self.logger.critical('No student class number')
return
if not self.school:
self.logger.critical('No school name')
return
status = 2 # 2 已更新验光仪数据
info = ['', student_id, name, gender, birthday, self.province, self.city, self.county,
self.school, grade, class_name, status] + [None for i in range(13)] # 补充25元素的学生信息
self.parent().locale_students_in_database.append(info)
self.logger.info(f'Add new student {student_id} {name}')
return info
def update_corrected_vision(self):
if self.tableWidget.currentRow() == 2: # 第三行为矫正视力
info = self._get_current_student_all_data()
if not info:
return
cell_item = self.tableWidget.currentItem()
if isinstance(cell_item, QtWidgets.QTableWidgetItem):
txt = cell_item.text()
if qt.isNumber(txt):
col = self.tableWidget.currentColumn()
if col == 1:
info[13] = txt
elif col == 2:
info[15] = txt
def vision_data_queried(self, vision):
self.current_vision = vision
self.vision_chart_timer.start(300)
def deal_vision_data(self):
self.vision_chart_timer.stop()
user_id = self.current_vision.get('ID')
info = self._get_student_by_id(user_id)
if info:
previous_vision = (info[12], info[13], info[14], info[15])
uncorrected_vision_od, uncorrected_vision_os, corrected_vision_od, corrected_vision_os = \
self.current_vision.get('OD').get('Uncorrected', None), \
self.current_vision.get('OS').get('Uncorrected', None), \
self.current_vision.get('OD').get('Corrected', None), \
self.current_vision.get('OS').get('Corrected', None)
# 数据库内第16列开始为验光数据, 第12列开始为视力表数据
# 莫廷视力表
if self.current_vision_query_mode == 0:
if uncorrected_vision_od:
info[12] = str(uncorrected_vision_od)
if uncorrected_vision_os:
info[14] = str(uncorrected_vision_os)
else:
if uncorrected_vision_od:
info[13] = str(uncorrected_vision_od)
if uncorrected_vision_os:
info[15] = str(uncorrected_vision_os)
# if corrected_vision_od:
# info[13] = str(corrected_vision_od)
# if corrected_vision_os:
# info[15] = str(corrected_vision_os)
if (info[12], info[13], info[14], info[15]) != previous_vision: # 数据变更后才去更新数据库
self.logger.info(f'Get vision data of {user_id}')
self.school = self.parent().current_school
thread = tasks.DatabaseOperation(self, DATABASE, self.school, info, update_data=True,
update_vision_data=True)
thread.error.connect(
lambda msg: QtWidgets.QMessageBox.critical(self, self.tr('Error'), msg,
QtWidgets.QMessageBox.Ok,
QtWidgets.QMessageBox.Ok))
thread.finished.connect(thread.deleteLater)
thread.finished.connect(self.update_btn_indicator)
thread.start()
# 刷新表格
self.initialize_table()
# 刷新按钮提示
QtCore.QTimer.singleShot(0, self.update_btn_indicator)
else:
if len(self.parent().locale_students_in_database): # 当有本地数据时进行log记录
self.logger.critical(f'Can not find student ID: {user_id}')
def optometry_data_queried(self, data):
# pd, s_od, c_od, a_od, se_od, s_os, c_os, a_os, se_os = data
if (num := len(data)) != 9:
self.logger.critical(f'Get wrong optometry data num: {num}, data:{data}')
QtWidgets.QMessageBox.critical(self, self.tr('Error'), self.tr('Get Wrong optometry data:\n%s') % data,
QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
return
user_id = self.current_vision.get('ID')
local_info = deepcopy(self._get_student_by_id(user_id))
self.school = self.parent().current_school
info = self.update_info(data, 16)
if local_info != info:
thread = tasks.DatabaseOperation(self, DATABASE, self.school, info, update_data=True,
update_optometry_data=True)
thread.error.connect(
lambda msg: QtWidgets.QMessageBox.critical(self, self.tr('Error'), msg,
QtWidgets.QMessageBox.Ok,
QtWidgets.QMessageBox.Ok))
thread.finished.connect(thread.deleteLater)
thread.start()
# 刷新表格
self.initialize_table()
# 刷新按钮提示
QtCore.QTimer.singleShot(0, self.update_btn_indicator)
def _get_student_by_id(self, stu_id: str):
if stu_id:
for item in self.parent().locale_students_in_database:
if stu_id in item:
return item
return []
def _get_current_student_all_data(self):
if self.student:
name = self.student.get('name', '')
gender = self.student.get('gender', '')
birthday = self.student.get('birthday', '')
student_id = self.student.get('id_card', '')
school = self.student.get('school_name', '')
grade = self.student.get('grade_name', '')
class_name = self.student.get('class_name', '')
for item in self.parent().locale_students_in_database:
match = True
for tag in (name, gender, birthday, student_id, school, grade, class_name):
if tag not in item:
match = False
break
if match:
return item
return []
def has_optometry_obtained(self, update_btn=False):
info = self._get_current_student_all_data()
if not info:
return False
if not update_btn:
# 开始mrt检查时判断表格内验光仪数据是否正确
pd = self.tableWidget.item(0, 1).text().strip()
if not qt.isNumber(pd):
QtWidgets.QMessageBox.critical(self, self.tr('Error'),
self.tr('Value of PD be a number! Please input again'),
QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
return False
s_od = self.tableWidget.item(3, 1).text().strip()
c_od = self.tableWidget.item(4, 1).text().strip()
a_od = self.tableWidget.item(5, 1).text().strip()
se_od = self.tableWidget.item(6, 1).text().strip()
s_os = self.tableWidget.item(3, 2).text().strip()
c_os = self.tableWidget.item(4, 2).text().strip()
a_os = self.tableWidget.item(5, 2).text().strip()
se_os = self.tableWidget.item(6, 2).text().strip()
optometry = []
for v in (s_od, c_od, a_od, se_od, s_os, c_os, a_os, se_os): # 不考虑pd
if v == '':
v = None
optometry.append(v)
# 检查是否手动变更了数据,若变更则更新数据库
modified = False
new_values = (pd, s_od, c_od, a_od, se_od, s_os, c_os, a_os, se_os)
for table_value, database_value in zip(new_values, info[16:25]):
if table_value != database_value:
modified = True
break
if modified:
info = self.update_info(new_values, 16)
thread = tasks.DatabaseOperation(self, DATABASE, self.school, info, update_data=True,
update_optometry_data=True)
thread.error.connect(
lambda msg: QtWidgets.QMessageBox.critical(self, self.tr('Error'), msg,
QtWidgets.QMessageBox.Ok,
QtWidgets.QMessageBox.Ok))
thread.finished.connect(thread.deleteLater)
thread.start()
else:
# 下面代码刷新按钮时判断用
optometry = info[17:25] # 不考虑pd
if optometry.count(None) > 4:
return False
return True
def has_vision_obtained(self):
uncorrected_vision_od = self.tableWidget.item(1, 1).text().strip()
uncorrected_vision_os = self.tableWidget.item(1, 2).text().strip()
corrected_vision_od = self.tableWidget.item(2, 1).text().strip()
corrected_vision_os = self.tableWidget.item(2, 2).text().strip()
if corrected_vision_od == '':
corrected_vision_od = None
if corrected_vision_os == '':
corrected_vision_os = None
tag = (self.tr('OD') + ' ' + self.tr('Uncorrected Vision'),
self.tr('OS') + ' ' + self.tr('Uncorrected Vision'),
self.tr('OD') + ' ' + self.tr('Corrected Vision'),
self.tr('OS') + ' ' + self.tr('Corrected Vision'))
for name, vision in zip(tag, (uncorrected_vision_od, uncorrected_vision_os, corrected_vision_od,
corrected_vision_os)):
if name in tag[:2]:
if not (qt.isNumber(vision) and 4.0 <= abs(float(vision)) <= 5.3):
QtWidgets.QMessageBox.critical(self, self.tr('Error'),
self.tr('Value of %s must be a number within 4.0 and 5.3!\n'
'Please input again') % name,
QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
return False
else:
if vision and not (qt.isNumber(vision) and 4.0 <= abs(float(vision)) <= 5.3):
QtWidgets.QMessageBox.critical(self, self.tr('Error'),
self.tr('Value of %s must be a number within 4.0 and 5.3!\n'
'Please input again') % name,
QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
return False
info = self.update_info(
[uncorrected_vision_od, corrected_vision_od, uncorrected_vision_os, corrected_vision_os], 12)
thread = tasks.DatabaseOperation(self, DATABASE, self.school, info, update_data=True, update_vision_data=True)
thread.error.connect(
lambda msg: QtWidgets.QMessageBox.critical(self, self.tr('Error'), msg,
QtWidgets.QMessageBox.Ok,
QtWidgets.QMessageBox.Ok))
thread.finished.connect(thread.deleteLater)
# thread.finished.connect(lambda :print(self.parent().locale_students_in_database))
thread.start()
return True
def orthanc_queried(self, patients):
if hasattr(self.parent(), 'recent_students_in_orthanc'):
self.parent().recent_students_in_orthanc = patients
def start_mrt(self):
# 先检查视力表数据是否就绪
if self.checkBox_Visual_Acuity_Required.isChecked() and not self.has_vision_obtained():
return
# 检查验光仪数据是否就绪
if self.checkBox_Optometry_Required.isChecked() and not self.has_optometry_obtained():
QtWidgets.QMessageBox.critical(self, self.tr('Error'),
self.tr('Optometry data has not been acquired'),
QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
return
# 发送数据到设备新建信息
info = self._get_current_student_all_data()
if not info:
QtWidgets.QMessageBox.critical(self, self.tr('Error'),
self.tr('Can not find %s') % self.student.get('name', ''),
QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
return
self.ready.emit(info, self.student)
self.close()
def closeEvent(self, evt):
self.dialog_closed.emit()
evt.accept()
def acquire_vision_data_manually(self):
if self.sender() == self.pushButton_Acquire_Uncorrected_Data:
self.current_vision_query_mode = 0
elif self.sender() == self.pushButton_Acquire_Corrected_Data:
self.current_vision_query_mode = 1
if not self.vision_chart_query_thread.isRunning():
self.logger.info(f'Querying vision data, query mode: {self.current_vision_query_mode}')
self.vision_chart_query_thread.start()
else:
QtWidgets.QMessageBox.warning(self, self.tr('Warning'),
self.tr('Query task is running, please try later!'),
QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Ok)
self.logger.info(f'Query thread is still running')
@staticmethod
def calculate_vision(vision):
if not vision or not qt.isNumber(vision):
return None
v = float(vision)
if 0.1 <= v < 0.12:
v = 4.0
elif 0.12 <= v < 0.15:
v = 4.1
elif 0.15 <= v < 0.2:
v = 4.2
elif 0.2 <= v < 0.25:
v = 4.3
elif 0.25 <= v < 0.3:
v = 4.4
elif 0.3 <= v < 0.4:
v = 4.5
elif 0.4 <= v < 0.5:
v = 4.6
elif 0.5 <= v < 0.6:
v = 4.7
elif 0.6 <= v < 0.8:
v = 4.8
elif 0.8 <= v < 1.0:
v = 4.9
elif 1.0 <= v < 1.2:
v = 5.0
elif 1.2 <= v < 1.5:
v = 5.1
elif v >= 1.5:
v = 5.2
if not 4.0 <= v <= 5.2:
return None
return v
if __name__ == '__main__':
# app = QtWidgets.QApplication([])
# win = StudyStatus(student={'id_card': '1243568', 'name': 'wwww', 'gender': 'Male', 'birthday': '2007/12/04'})
# win.show()
# app.exec_()
pass
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化