Moved relevant reagent lot aggregator to KitTypeReagentRole object.

This commit is contained in:
lwark
2024-09-17 14:50:04 -05:00
parent 7c3dfd53a0
commit 0cb1d3a104
7 changed files with 60 additions and 44 deletions

View File

@@ -14,7 +14,7 @@ from sqlalchemy.orm import relationship, validates, Query
from sqlalchemy.ext.associationproxy import association_proxy
from datetime import date
import logging, re
from tools import check_authorization, setup_lookup, Report, Result, jinja_template_loading
from tools import check_authorization, setup_lookup, Report, Result, jinja_template_loading, check_regex_match
from typing import List, Literal, Generator, Any
from pandas import ExcelFile
from pathlib import Path
@@ -175,7 +175,7 @@ class KitType(BaseClass):
return [item.reagent_role for item in relevant_associations]
# TODO: Move to BasicSubmission?
def construct_xl_map_for_use(self, submission_type: str | SubmissionType) -> Generator[str, str]:
def construct_xl_map_for_use(self, submission_type: str | SubmissionType) -> Generator[(str, str)]:
"""
Creates map of locations in Excel workbook for a SubmissionType
@@ -1139,6 +1139,23 @@ class KitTypeReagentRoleAssociation(BaseClass):
base_dict[k] = v
return base_dict
def get_all_relevant_reagents(self) -> Generator[Reagent, None, None]:
"""
Creates a generator that will resolve in to a list filling the role associated with this object.
Returns:
Generator: Generates of reagents.
"""
# logger.debug(f"Attempting lookup of reagents by type: {reagent.type}")
reagents = self.reagent_role.instances
try:
regex = self.uses['exclude_regex']
except KeyError:
regex = "^$"
relevant_reagents = [reagent for reagent in reagents if
not check_regex_match(pattern=regex, check=str(reagent.lot))]
for rel_reagent in relevant_reagents:
yield rel_reagent
class SubmissionReagentAssociation(BaseClass):
"""