Bug fixing for new AddEdit forms.

This commit is contained in:
lwark
2025-01-08 13:54:14 -06:00
parent 8662bbdc2f
commit 95ae203cc2
11 changed files with 217 additions and 85 deletions

View File

@@ -243,7 +243,10 @@ class BaseClass(Base):
@classmethod
def get_pydantic_model(cls):
from backend.validators import pydant
model = getattr(pydant, f"Pyd{cls.__name__}")
try:
model = getattr(pydant, f"Pyd{cls.__name__}")
except AttributeError:
return None
return model

View File

@@ -286,6 +286,10 @@ class Control(BaseClass):
"""
return None
def delete(self):
self.__database_session__.delete(self)
self.__database_session__.commit()
class PCRControl(Control):
"""
@@ -296,7 +300,7 @@ class PCRControl(Control):
subtype = Column(String(16)) #: PC or NC
target = Column(String(16)) #: N1, N2, etc.
ct = Column(FLOAT) #: PCR result
reagent_lot = Column(String(64), ForeignKey("_reagent.name", ondelete="SET NULL",
reagent_lot = Column(String(64), ForeignKey("_reagent.lot", ondelete="SET NULL",
name="fk_reagent_lot"))
reagent = relationship("Reagent", foreign_keys=reagent_lot) #: reagent used for this control

View File

@@ -540,6 +540,24 @@ class Reagent(BaseClass, LogMixin):
report.add_result(Result(msg=f"Updating last used {rt} was not performed.", status="Information"))
return report
@classmethod
def query_or_create(cls, **kwargs) -> Reagent:
from backend.validators.pydant import PydReagent
new = False
instance = cls.query(**kwargs)
if not instance or isinstance(instance, list):
if "role" not in kwargs:
try:
kwargs['role'] = kwargs['name']
except KeyError:
pass
instance = PydReagent(**kwargs)
new = True
instance, _ = instance.toSQL()
logger.debug(f"Instance: {instance}")
return instance, new
@classmethod
@setup_lookup
def query(cls,

View File

@@ -936,14 +936,20 @@ class BasicSubmission(BaseClass, LogMixin):
Generator[dict, None, None]: Dictionaries of row values.
"""
location_map = cls.get_submission_type().sample_map['pcr_controls']
# logger.debug(f"Location map: {location_map}")
submission = cls.query(rsl_plate_num=rsl_plate_num)
name_column = 1
for item in location_map:
logger.debug(f"Checking {item}")
worksheet = xl[item['sheet']]
for iii, row in enumerate(worksheet.iter_rows(max_row=len(worksheet['A']), max_col=name_column), start=1):
logger.debug(f"Checking row {row}, {iii}")
for cell in row:
logger.debug(f"Checking cell: {cell}, with value {cell.value} against {item['name']}")
if cell.value == item['name']:
subtype, target = item['name'].split("-")
subtype, _ = item['name'].split("-")
target = item['target']
logger.debug(f"Subtype: {subtype}, target: {target}")
ct = worksheet.cell(row=iii, column=item['ct_column']).value
# NOTE: Kind of a stop gap solution to find control reagents.
if subtype == "PC":
@@ -955,6 +961,9 @@ class BasicSubmission(BaseClass, LogMixin):
ctrl = next((assoc.reagent for assoc in submission.submission_reagent_associations
if any(["molecular grade water" in item.name.lower() for item in
assoc.reagent.role])), None)
else:
ctrl = None
logger.debug(f"Control reagent: {ctrl.__dict__}")
try:
ct = float(ct)
except ValueError:
@@ -963,13 +972,15 @@ class BasicSubmission(BaseClass, LogMixin):
ctrl = ctrl.lot
else:
ctrl = None
yield dict(
name=f"{rsl_plate_num}<{item['name']}>",
output = dict(
name=f"{rsl_plate_num}<{item['name']}-{target}>",
ct=ct,
subtype=subtype,
target=target,
reagent_lot=ctrl
)
logger.debug(f"Control output: {pformat(output)}")
yield output
@classmethod
def filename_template(cls) -> str:
@@ -1663,10 +1674,12 @@ class Wastewater(BasicSubmission):
submitted_date = datetime.strptime(" ".join(parser.pcr['run_start_date/time'].split(" ")[:-1]),
"%Y-%m-%d %I:%M:%S %p")
for control in pcr_controls:
logger.debug(f"Control coming into save: {control}")
new_control = PCRControl(**control)
new_control.submitted_date = submitted_date
new_control.controltype = controltype
new_control.submission = self
logger.debug(f"Control coming into save: {new_control.__dict__}")
new_control.save()
return report