Renaming ReagentType to ReagentRole

This commit is contained in:
lwark
2024-06-07 14:15:19 -05:00
parent a355c5bb76
commit c7b6c90eac
8 changed files with 197 additions and 129 deletions

View File

@@ -13,24 +13,27 @@ logger = logging.getLogger(f"submissions.{__name__}")
# table containing organization/contact relationship
orgs_contacts = Table(
"_orgs_contacts",
Base.metadata,
Column("org_id", INTEGER, ForeignKey("_organization.id")),
Column("contact_id", INTEGER, ForeignKey("_contact.id")),
# __table_args__ = {'extend_existing': True}
extend_existing = True
)
"_orgs_contacts",
Base.metadata,
Column("org_id", INTEGER, ForeignKey("_organization.id")),
Column("contact_id", INTEGER, ForeignKey("_contact.id")),
# __table_args__ = {'extend_existing': True}
extend_existing=True
)
class Organization(BaseClass):
"""
Base of organization
"""
id = Column(INTEGER, primary_key=True) #: primary key
name = Column(String(64)) #: organization name
submissions = relationship("BasicSubmission", back_populates="submitting_lab") #: submissions this organization has submitted
cost_centre = Column(String()) #: cost centre used by org for payment
contacts = relationship("Contact", back_populates="organization", secondary=orgs_contacts) #: contacts involved with this org
id = Column(INTEGER, primary_key=True) #: primary key
name = Column(String(64)) #: organization name
submissions = relationship("BasicSubmission",
back_populates="submitting_lab") #: submissions this organization has submitted
cost_centre = Column(String()) #: cost centre used by org for payment
contacts = relationship("Contact", back_populates="organization",
secondary=orgs_contacts) #: contacts involved with this org
def __repr__(self) -> str:
return f"<Organization({self.name})>"
@@ -38,10 +41,10 @@ class Organization(BaseClass):
@classmethod
@setup_lookup
def query(cls,
id:int|None=None,
name:str|None=None,
limit:int=0,
) -> Organization|List[Organization]:
id: int | None = None,
name: str | None = None,
limit: int = 0,
) -> Organization | List[Organization]:
"""
Lookup organizations in the database by a number of parameters.
@@ -51,11 +54,11 @@ class Organization(BaseClass):
Returns:
Organization|List[Organization]:
"""
"""
query: Query = cls.__database_session__.query(cls)
match id:
case int():
query = query.filter(cls.id==id)
query = query.filter(cls.id == id)
limit = 1
case _:
pass
@@ -73,33 +76,35 @@ class Organization(BaseClass):
def save(self):
super().save()
class Contact(BaseClass):
"""
Base of Contact
"""
id = Column(INTEGER, primary_key=True) #: primary key
name = Column(String(64)) #: contact name
email = Column(String(64)) #: contact email
phone = Column(String(32)) #: contact phone number
organization = relationship("Organization", back_populates="contacts", uselist=True, secondary=orgs_contacts) #: relationship to joined organization
submissions = relationship("BasicSubmission", back_populates="contact") #: submissions this contact has submitted
id = Column(INTEGER, primary_key=True) #: primary key
name = Column(String(64)) #: contact name
email = Column(String(64)) #: contact email
phone = Column(String(32)) #: contact phone number
organization = relationship("Organization", back_populates="contacts", uselist=True,
secondary=orgs_contacts) #: relationship to joined organization
submissions = relationship("BasicSubmission", back_populates="contact") #: submissions this contact has submitted
def __repr__(self) -> str:
"""
Returns:
str: Representation of this Contact
"""
"""
return f"<Contact({self.name})>"
@classmethod
@setup_lookup
def query(cls,
name:str|None=None,
email:str|None=None,
phone:str|None=None,
limit:int=0,
) -> Contact|List[Contact]:
def query(cls,
name: str | None = None,
email: str | None = None,
phone: str | None = None,
limit: int = 0,
) -> Contact | List[Contact]:
"""
Lookup contacts in the database by a number of parameters.
@@ -111,29 +116,28 @@ class Contact(BaseClass):
Returns:
Contact|List[Contact]: Contact(s) of interest.
"""
"""
# super().query(session)
query: Query = cls.__database_session__.query(cls)
match name:
case str():
# logger.debug(f"Looking up contact with name: {name}")
query = query.filter(cls.name==name)
query = query.filter(cls.name == name)
limit = 1
case _:
pass
match email:
case str():
# logger.debug(f"Looking up contact with email: {name}")
query = query.filter(cls.email==email)
query = query.filter(cls.email == email)
limit = 1
case _:
pass
match phone:
case str():
# logger.debug(f"Looking up contact with phone: {name}")
query = query.filter(cls.phone==phone)
query = query.filter(cls.phone == phone)
limit = 1
case _:
pass
return cls.execute_query(query=query, limit=limit)

View File

@@ -248,6 +248,7 @@ class BasicSubmission(BaseClass):
ext_info = self.extraction_info
except TypeError:
ext_info = None
output = {
"id": self.id,
"plate_number": self.rsl_plate_num,
@@ -257,8 +258,7 @@ class BasicSubmission(BaseClass):
"submitting_lab": sub_lab,
"sample_count": self.sample_count,
"extraction_kit": ext_kit,
"cost": self.run_cost,
"cost": self.run_cost
}
if report:
return output
@@ -299,6 +299,15 @@ class BasicSubmission(BaseClass):
except Exception as e:
logger.error(f"Error setting comment: {self.comment}, {e}")
comments = None
try:
contact = self.contact.name
except AttributeError as e:
logger.error(f"Problem setting contact: {e}")
contact = "NA"
try:
contact_phone = self.contact.phone
except AttributeError:
contact_phone = "NA"
output["submission_category"] = self.submission_category
output["technician"] = self.technician
output["reagents"] = reagents
@@ -308,9 +317,9 @@ class BasicSubmission(BaseClass):
output["equipment"] = equipment
output["cost_centre"] = cost_centre
output["signed_by"] = self.signed_by
output["contact"] = self.contact.name
output["contact_phone"] = self.contact.phone
# logger.debug(f"Setting contact to: {contact} of type: {type(contact)}")
output["contact"] = contact
output["contact_phone"] = contact_phone
return output
def calculate_column_count(self) -> int:
@@ -431,7 +440,7 @@ class BasicSubmission(BaseClass):
excluded = ['controls', 'extraction_info', 'pcr_info', 'comment', 'comments', 'samples', 'reagents',
'equipment', 'gel_info', 'gel_image', 'dna_core_submission_number', 'gel_controls',
'source_plates', 'pcr_technician', 'ext_technician', 'artic_technician', 'cost_centre',
'signed_by']
'signed_by', 'artic_date', 'gel_barcode', 'gel_date', 'ngs_date', 'contact_phone', 'contact']
for item in excluded:
try:
df = df.drop(item, axis=1)
@@ -544,7 +553,6 @@ class BasicSubmission(BaseClass):
# logger.debug("To dict complete")
new_dict = {}
for key, value in dicto.items():
# start = time()
# logger.debug(f"Checking {key}")
missing = value is None or value in ['', 'None']
match key:
@@ -1403,6 +1411,10 @@ class WastewaterArtic(BasicSubmission):
gel_info = Column(JSON) #: unstructured data from gel.
gel_controls = Column(JSON) #: locations of controls on the gel
source_plates = Column(JSON) #: wastewater plates that samples come from
artic_date = Column(TIMESTAMP) #: Date Artic Performed
ngs_date = Column(TIMESTAMP) #: Date submission received
gel_date = Column(TIMESTAMP) #: Date submission received
gel_barcode = Column(String(16))
__mapper_args__ = dict(polymorphic_identity="Wastewater Artic",
polymorphic_load="inline",
@@ -1418,12 +1430,18 @@ class WastewaterArtic(BasicSubmission):
output = super().to_dict(full_data=full_data, backup=backup, report=report)
if self.artic_technician in [None, "None"]:
output['artic_technician'] = self.technician
else:
output['artic_technician'] = self.artic_technician
if report:
return output
output['gel_info'] = self.gel_info
output['gel_image'] = self.gel_image
output['dna_core_submission_number'] = self.dna_core_submission_number
output['source_plates'] = self.source_plates
output['artic_date'] = self.artic_date or self.submitted_date
output['ngs_date'] = self.ngs_date or self.submitted_date
output['gel_date'] = self.gel_date or self.submitted_date
output['gel_barcode'] = self.gel_barcode
return output
@classmethod
@@ -1756,19 +1774,22 @@ class WastewaterArtic(BasicSubmission):
output.append(dicto)
continue
for item in self.source_plates:
old_plate = WastewaterAssociation.query(submission=item['plate'], sample=assoc.sample, limit=1)
if assoc.sample.id is None:
old_plate = None
else:
old_plate = WastewaterAssociation.query(submission=item['plate'], sample=assoc.sample, limit=1)
if old_plate is not None:
set_plate = old_plate.submission.rsl_plate_num
logger.debug(dicto['WW Processing Num'])
if dicto['WW Processing Num'].startswith("NTC"):
dicto['Well'] = dicto['WW Processing Num']
# logger.debug(f"Dictionary: {pformat(dicto)}")
if dicto['ww_processing_num'].startswith("NTC"):
dicto['well'] = dicto['ww_processing_num']
else:
dicto['Well'] = f"{row_map[old_plate.row]}{old_plate.column}"
dicto['well'] = f"{row_map[old_plate.row]}{old_plate.column}"
break
elif dicto['WW Processing Num'].startswith("NTC"):
dicto['Well'] = dicto['WW Processing Num']
elif dicto['ww_processing_num'].startswith("NTC"):
dicto['well'] = dicto['ww_processing_num']
dicto['plate_name'] = set_plate
logger.debug(f"Here is our raw sample: {pformat(dicto)}")
# logger.debug(f"Here is our raw sample: {pformat(dicto)}")
output.append(dicto)
return output
@@ -1801,7 +1822,7 @@ class WastewaterArtic(BasicSubmission):
fname = select_open_file(obj=obj, file_extension="jpg")
dlg = GelBox(parent=obj, img_path=fname, submission=self)
if dlg.exec():
self.dna_core_submission_number, img_path, output, comment = dlg.parse_form()
self.dna_core_submission_number, self.gel_barcode, img_path, output, comment = dlg.parse_form()
self.gel_image = img_path.name
self.gel_info = output
dt = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
@@ -2135,7 +2156,7 @@ class BasicSample(BaseClass):
if dlg.exec():
pass
#Below are the custom sample types
# Below are the custom sample types
class WastewaterSample(BasicSample):
"""
@@ -2235,6 +2256,7 @@ class WastewaterSample(BasicSample):
searchables.append(dict(label=label, field=item))
return searchables
class BacterialCultureSample(BasicSample):
"""
base of bacterial culture sample