Renaming ReagentType to ReagentRole
This commit is contained in:
@@ -83,6 +83,7 @@ class Contact(BaseClass):
|
||||
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:
|
||||
"""
|
||||
|
||||
@@ -10,7 +10,7 @@ from zipfile import ZipFile
|
||||
from tempfile import TemporaryDirectory
|
||||
from operator import attrgetter, itemgetter
|
||||
from pprint import pformat
|
||||
from . import BaseClass, Reagent, SubmissionType, KitType, Organization
|
||||
from . import BaseClass, Reagent, SubmissionType, KitType, Organization, Contact
|
||||
from sqlalchemy import Column, String, TIMESTAMP, INTEGER, ForeignKey, JSON, FLOAT, case
|
||||
from sqlalchemy.orm import relationship, validates, Query
|
||||
from sqlalchemy.orm.attributes import flag_modified
|
||||
@@ -65,6 +65,9 @@ class BasicSubmission(BaseClass):
|
||||
String(64)) #: ["Research", "Diagnostic", "Surveillance", "Validation"], else defaults to submission_type_name
|
||||
cost_centre = Column(
|
||||
String(64)) #: Permanent storage of used cost centre in case organization field changed in the future.
|
||||
contact = relationship("Contact", back_populates="submissions") #: client org
|
||||
contact_id = Column(INTEGER, ForeignKey("_contact.id", ondelete="SET NULL",
|
||||
name="fk_BS_contact_id")) #: client lab id from _organizations
|
||||
|
||||
submission_sample_associations = relationship(
|
||||
"SubmissionSampleAssociation",
|
||||
@@ -255,6 +258,7 @@ class BasicSubmission(BaseClass):
|
||||
"sample_count": self.sample_count,
|
||||
"extraction_kit": ext_kit,
|
||||
"cost": self.run_cost,
|
||||
|
||||
}
|
||||
if report:
|
||||
return output
|
||||
@@ -304,6 +308,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
|
||||
|
||||
return output
|
||||
|
||||
def calculate_column_count(self) -> int:
|
||||
@@ -453,6 +460,8 @@ class BasicSubmission(BaseClass):
|
||||
# logger.debug(f"Looking up organization: {value}")
|
||||
field_value = Organization.query(name=value)
|
||||
# logger.debug(f"Got {field_value} for organization {value}")
|
||||
case "contact":
|
||||
field_value = Contact.query(name=value)
|
||||
case "samples":
|
||||
for sample in value:
|
||||
# logger.debug(f"Parsing {sample} to sql.")
|
||||
@@ -1196,7 +1205,7 @@ class BacterialCulture(BasicSubmission):
|
||||
new_lot = matched.group()
|
||||
try:
|
||||
pos_control_reg = \
|
||||
[reg for reg in input_dict['reagents'] if reg['type'] == "Bacterial-Positive Control"][0]
|
||||
[reg for reg in input_dict['reagents'] if reg['role'] == "Bacterial-Positive Control"][0]
|
||||
except IndexError:
|
||||
logger.error(f"No positive control reagent listed")
|
||||
return input_dict
|
||||
|
||||
@@ -148,7 +148,7 @@ class ReagentWriter(object):
|
||||
output = []
|
||||
for reagent in reagent_list:
|
||||
try:
|
||||
mp_info = map[reagent['type']]
|
||||
mp_info = map[reagent['role']]
|
||||
except KeyError:
|
||||
continue
|
||||
placeholder = copy(reagent)
|
||||
|
||||
@@ -104,7 +104,7 @@ class PydReagent(BaseModel):
|
||||
if value != None:
|
||||
return convert_nans_to_nones(str(value))
|
||||
else:
|
||||
return values.data['type']
|
||||
return values.data['role']
|
||||
|
||||
def improved_dict(self) -> dict:
|
||||
try:
|
||||
@@ -123,7 +123,7 @@ class PydReagent(BaseModel):
|
||||
# output[k] = value
|
||||
return {k: getattr(self, k) for k in fields}
|
||||
|
||||
def toSQL(self, submission: BasicSubmission | str = None) -> Tuple[Reagent, SubmissionReagentAssociation]:
|
||||
def toSQL(self, submission: BasicSubmission | str = None) -> Tuple[Reagent, SubmissionReagentAssociation, Report]:
|
||||
"""
|
||||
Converts this instance into a backend.db.models.kit.Reagent instance
|
||||
|
||||
@@ -168,6 +168,7 @@ class PydReagent(BaseModel):
|
||||
# reagent.reagent_submission_associations.append(assoc)
|
||||
else:
|
||||
assoc = None
|
||||
report.add_result(Result(owner = __name__, code=0, msg="New reagent created.", status="Information"))
|
||||
else:
|
||||
if submission is not None and reagent not in submission.reagents:
|
||||
assoc = SubmissionReagentAssociation(reagent=reagent, submission=submission)
|
||||
@@ -177,7 +178,8 @@ class PydReagent(BaseModel):
|
||||
assoc = None
|
||||
# add end-of-life extension from reagent type to expiry date
|
||||
# NOTE: this will now be done only in the reporting phase to account for potential changes in end-of-life extensions
|
||||
return reagent, assoc
|
||||
|
||||
return reagent, assoc, report
|
||||
|
||||
|
||||
class PydSample(BaseModel, extra='allow'):
|
||||
@@ -353,6 +355,7 @@ class PydSubmission(BaseModel, extra='allow'):
|
||||
samples: List[PydSample]
|
||||
equipment: List[PydEquipment] | None = []
|
||||
cost_centre: dict | None = Field(default=dict(value=None, missing=True), validate_default=True)
|
||||
contact: dict | None = Field(default=dict(value=None, missing=True), validate_default=True)
|
||||
|
||||
@field_validator('equipment', mode='before')
|
||||
@classmethod
|
||||
@@ -567,6 +570,17 @@ class PydSubmission(BaseModel, extra='allow'):
|
||||
case _:
|
||||
return value
|
||||
|
||||
@field_validator("contact")
|
||||
@classmethod
|
||||
def get_contact_from_org(cls, value, values):
|
||||
check = Contact.query(name=value['value'])
|
||||
if check is None:
|
||||
org = Organization.query(name=values.data['submitting_lab']['value'])
|
||||
contact = org.contacts[0].name
|
||||
return dict(value=contact, missing=True)
|
||||
else:
|
||||
return value
|
||||
|
||||
def __init__(self, **data):
|
||||
super().__init__(**data)
|
||||
# this could also be done with default_factory
|
||||
@@ -664,7 +678,7 @@ class PydSubmission(BaseModel, extra='allow'):
|
||||
instance.submission_reagent_associations = []
|
||||
# logger.debug(f"Looking through {self.reagents}")
|
||||
for reagent in self.reagents:
|
||||
reagent, assoc = reagent.toSQL(submission=instance)
|
||||
reagent, assoc, _ = reagent.toSQL(submission=instance)
|
||||
# logger.debug(f"Association: {assoc}")
|
||||
if assoc is not None:# and assoc not in instance.submission_reagent_associations:
|
||||
instance.submission_reagent_associations.append(assoc)
|
||||
|
||||
Reference in New Issue
Block a user