Moments before disaster.

This commit is contained in:
lwark
2025-01-16 08:36:15 -06:00
parent 5cded949ed
commit bf711369c6
21 changed files with 541 additions and 368 deletions

View File

@@ -193,7 +193,7 @@ class App(QMainWindow):
@check_authorization
def edit_reagent(self, *args, **kwargs):
dlg = SearchBox(parent=self, object_type=Reagent, extras=['role'])
dlg = SearchBox(parent=self, object_type=Reagent, extras=[dict(name='Role', field="role")])
dlg.exec()
@check_authorization

View File

@@ -30,8 +30,7 @@ class ControlsViewer(InfoPane):
self.control_sub_typer.addItems(con_sub_types)
# NOTE: create custom widget to get types of analysis -- disabled by PCR control
self.mode_typer = QComboBox()
mode_types = IridaControl.get_modes()
self.mode_typer.addItems(mode_types)
self.mode_typer.addItems(IridaControl.modes)
# NOTE: create custom widget to get subtypes of analysis -- disabled by PCR control
self.mode_sub_typer = QComboBox()
self.mode_sub_typer.setEnabled(False)
@@ -43,7 +42,7 @@ class ControlsViewer(InfoPane):
self.layout.addWidget(self.control_sub_typer, 1, 0, 1, 4)
self.layout.addWidget(self.mode_typer, 2, 0, 1, 4)
self.layout.addWidget(self.mode_sub_typer, 3, 0, 1, 4)
self.archetype.get_instance_class().make_parent_buttons(parent=self)
self.archetype.instance_class.make_parent_buttons(parent=self)
self.update_data()
self.control_sub_typer.currentIndexChanged.connect(self.update_data)
self.mode_typer.currentIndexChanged.connect(self.update_data)
@@ -70,7 +69,7 @@ class ControlsViewer(InfoPane):
except AttributeError:
sub_types = []
# NOTE: added in allowed to have subtypes in case additions made in future.
if sub_types and self.mode.lower() in self.archetype.get_instance_class().subtyping_allowed:
if sub_types and self.mode.lower() in self.archetype.instance_class.subtyping_allowed:
# NOTE: block signal that will rerun controls getter and update mode_sub_typer
with QSignalBlocker(self.mode_sub_typer) as blocker:
self.mode_sub_typer.addItems(sub_types)
@@ -103,7 +102,7 @@ class ControlsViewer(InfoPane):
chart_settings = dict(sub_type=self.con_sub_type, start_date=self.start_date, end_date=self.end_date,
mode=self.mode,
sub_mode=self.mode_sub_type, parent=self, months=months)
self.fig = self.archetype.get_instance_class().make_chart(chart_settings=chart_settings, parent=self, ctx=self.app.ctx)
self.fig = self.archetype.instance_class.make_chart(chart_settings=chart_settings, parent=self, ctx=self.app.ctx)
self.report_obj = ChartReportMaker(df=self.fig.df, sheet_name=self.archetype.name)
if issubclass(self.fig.__class__, CustomFigure):
self.save_button.setEnabled(True)

View File

@@ -19,7 +19,7 @@ class EquipmentUsage(QDialog):
super().__init__(parent)
self.submission = submission
self.setWindowTitle(f"Equipment Checklist - {submission.rsl_plate_num}")
self.used_equipment = self.submission.get_used_equipment()
self.used_equipment = self.submission.used_equipment
self.kit = self.submission.extraction_kit
self.opt_equipment = submission.submission_type.get_equipment()
self.layout = QVBoxLayout()

View File

@@ -65,11 +65,11 @@ class AddEdit(QDialog):
report = Report()
parsed = {result[0].strip(":"): result[1] for result in [item.parse_form() for item in self.findChildren(EditProperty)] if result[0]}
logger.debug(parsed)
model = self.object_type.get_pydantic_model()
model = self.object_type.pydantic_model
# NOTE: Hand-off to pydantic model for validation.
# NOTE: Also, why am I not just using the toSQL method here. I could write one for contacts.
model = model(**parsed)
# output, result = model.toSQL()
# output, result = model.to_sql()
# report.add_result(result)
# if len(report.results) < 1:
# report.add_result(Result(msg="Added new regeant.", icon="Information", owner=__name__))

View File

@@ -188,7 +188,7 @@ class EditRelationship(QWidget):
dlg = AddEdit(self, instance=instance, manager=self.parent().object_type.__name__.lower())
if dlg.exec():
new_instance = dlg.parse_form()
new_instance, result = new_instance.toSQL()
new_instance, result = new_instance.to_sql()
logger.debug(f"New instance: {new_instance}")
addition = getattr(self.parent().instance, self.objectName())
if isinstance(addition, InstrumentedList):
@@ -213,7 +213,7 @@ class EditRelationship(QWidget):
sets data in model
"""
# logger.debug(self.data)
self.data = DataFrame.from_records([item.to_omnigui_dict() for item in self.data])
self.data = DataFrame.from_records([item.omnigui_dict for item in self.data])
try:
self.columns_of_interest = [dict(name=item, column=self.data.columns.get_loc(item)) for item in self.extras]
except (KeyError, AttributeError):

View File

@@ -20,7 +20,7 @@ class SearchBox(QDialog):
The full search widget.
"""
def __init__(self, parent, object_type: Any, extras: List[str], returnable: bool = False, **kwargs):
def __init__(self, parent, object_type: Any, extras: List[dict], returnable: bool = False, **kwargs):
super().__init__(parent)
self.object_type = self.original_type = object_type
self.extras = extras
@@ -73,8 +73,9 @@ class SearchBox(QDialog):
except AttributeError:
search_fields = []
for iii, searchable in enumerate(search_fields):
widget = FieldSearch(parent=self, label=searchable, field_name=searchable)
widget.setObjectName(searchable)
widget = FieldSearch(parent=self, label=searchable['label'], field_name=searchable['field'])
# widget = FieldSearch(parent=self, label=k, field_name=v)
widget.setObjectName(searchable['field'])
self.layout.addWidget(widget, 1 + iii, 0)
widget.search_widget.textChanged.connect(self.update_data)
self.update_data()
@@ -150,14 +151,16 @@ class SearchResults(QTableView):
self.extras = extras + self.object_type.searchables
except AttributeError:
self.extras = extras
logger.debug(f"Extras: {self.extras}")
def setData(self, df: DataFrame) -> None:
"""
sets data in model
"""
self.data = df
try:
self.columns_of_interest = [dict(name=item, column=self.data.columns.get_loc(item)) for item in self.extras]
self.columns_of_interest = [dict(name=item['field'], column=self.data.columns.get_loc(item['field'])) for item in self.extras]
except KeyError:
self.columns_of_interest = []
try:

View File

@@ -93,7 +93,7 @@ class SubmissionDetails(QDialog):
base_dict = sample.to_sub_dict(full_data=True)
exclude = ['submissions', 'excluded', 'colour', 'tooltip']
base_dict['excluded'] = exclude
template = sample.get_details_template()
template = sample.details_template
template_path = Path(template.environment.loader.__getattribute__("searchpath")[0])
with open(template_path.joinpath("css", "styles.css"), "r") as f:
css = f.read()
@@ -147,7 +147,7 @@ class SubmissionDetails(QDialog):
self.rsl_plate_num = submission.rsl_plate_num
self.base_dict = submission.to_dict(full_data=True)
# NOTE: don't want id
self.base_dict['platemap'] = submission.make_plate_map(sample_list=submission.hitpick_plate())
self.base_dict['platemap'] = submission.make_plate_map(sample_list=submission.hitpicked)
self.base_dict['excluded'] = submission.get_default_info("details_ignore")
self.base_dict, self.template = submission.get_details_template(base_dict=self.base_dict)
template_path = Path(self.template.environment.loader.__getattribute__("searchpath")[0])

View File

@@ -147,14 +147,16 @@ class SubmissionFormContainer(QWidget):
instance = Reagent()
dlg = AddEdit(parent=self, instance=instance)
if dlg.exec():
reagent, result = dlg.parse_form()
reagent = dlg.parse_form()
reagent.missing = False
logger.debug(f"Reagent: {reagent}, result: {result}")
report.add_result(result)
# logger.debug(f"Reagent: {reagent}, result: {result}")
# report.add_result(result)
# NOTE: send reagent to db
sqlobj, result = reagent.toSQL()
sqlobj = reagent.to_sql()
sqlobj.save()
report.add_result(result)
logger.debug(f"Reagent added!")
report.add_result(Result(owner=__name__, code=0, msg="New reagent created.", status="Information"))
# report.add_result(result)
return reagent, report
@report_result
@@ -184,10 +186,10 @@ class SubmissionFormContainer(QWidget):
# NOTE: create reagent object
reagent = PydReagent(ctx=self.app.ctx, **info, missing=False)
# NOTE: send reagent to db
sqlobj, result = reagent.toSQL()
sqlobj = reagent.to_sql()
sqlobj.save()
report.add_result(result)
return reagent, report
# report.add_result(result)
return reagent
class SubmissionFormWidget(QWidget):
@@ -201,7 +203,7 @@ class SubmissionFormWidget(QWidget):
self.pyd = submission
self.missing_info = []
self.submission_type = SubmissionType.query(name=self.pyd.submission_type['value'])
st = self.submission_type.get_submission_class()
st = self.submission_type.submission_class
defaults = st.get_default_info("form_recover", "form_ignore", submission_type=self.pyd.submission_type['value'])
self.recover = defaults['form_recover']
self.ignore = defaults['form_ignore']
@@ -443,6 +445,9 @@ class SubmissionFormWidget(QWidget):
reagent = widget.parse_form()
if reagent is not None:
reagents.append(reagent)
else:
report.add_result(Result(msg="Failed integrity check", status="Critical"))
return report
case self.InfoItem():
field, value = widget.parse_form()
if field is not None:
@@ -523,7 +528,7 @@ class SubmissionFormWidget(QWidget):
if isinstance(submission_type, str):
submission_type = SubmissionType.query(name=submission_type)
if sub_obj is None:
sub_obj = submission_type.get_submission_class()
sub_obj = submission_type.submission_class
try:
value = value['value']
except (TypeError, KeyError):
@@ -585,7 +590,7 @@ class SubmissionFormWidget(QWidget):
add_widget.addItems(cats)
add_widget.setToolTip("Enter submission category or select from list.")
case _:
if key in sub_obj.timestamps():
if key in sub_obj.timestamps:
add_widget = MyQDateEdit(calendarPopup=True, scrollWidget=parent)
# NOTE: sets submitted date based on date found in excel sheet
try:
@@ -696,7 +701,7 @@ class SubmissionFormWidget(QWidget):
if not self.lot.isEnabled():
return None, report
lot = self.lot.currentText()
wanted_reagent, new = Reagent.query_or_create(lot=lot, role=self.reagent.role)
wanted_reagent, new = Reagent.query_or_create(lot=lot, role=self.reagent.role, expiry=self.reagent.expiry)
# NOTE: if reagent doesn't exist in database, offer to add it (uses App.add_reagent)
logger.debug(f"Wanted reagent: {wanted_reagent}, New: {new}")
# if wanted_reagent is None:
@@ -705,18 +710,13 @@ class SubmissionFormWidget(QWidget):
message=f"Couldn't find reagent type {self.reagent.role}: {lot} in the database.\n\nWould you like to add it?")
if dlg.exec():
# wanted_reagent = self.parent().parent().add_reagent(reagent_lot=lot,
# reagent_role=self.reagent.role,
# expiry=self.reagent.expiry,
# name=self.reagent.name,
# kit=self.extraction_kit
# )
wanted_reagent = self.parent().parent().new_add_reagent(instance=wanted_reagent)
logger.debug(f"Reagent added!")
report.add_result(Result(owner=__name__, code=0, msg="New reagent created.", status="Information"))
return wanted_reagent, report
else:
# NOTE: In this case we will have an empty reagent and the submission will fail kit integrity check
report.add_result(Result(msg="Failed integrity check", status="Critical"))
return None, report
else:
# NOTE: Since this now gets passed in directly from the parser -> pyd -> form and the parser gets the name