Skip to content

Commit

Permalink
Fallback to generic format for sample id format if no specific type d…
Browse files Browse the repository at this point in the history
…efined
  • Loading branch information
xispa committed Jul 8, 2024
1 parent 838520a commit 6c2f7f7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/senaite/referral/adapters/idserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
from zope.interface import implementer


SAMPLE_FROM_SHIPMENT_ID = "AnalysisRequestFromShipment"


@implementer(IIdServerVariables)
class IDServerVariablesAdapter(object):
"""An adapter for the generation of Variables for ID Server
Expand Down Expand Up @@ -73,7 +76,17 @@ class IDServerSampleTypeIDAdapter(object):
def __init__(self, context):
self.context = context

def has_custom_type_registered(self):
# get the ID formatting config
config_map = api.get_bika_setup().getIDFormatting()
for config in config_map:
portal_type = config["portal_type"]
if portal_type.lower() == SAMPLE_FROM_SHIPMENT_ID.lower():
return True
return False

def get_type_id(self, **kw):
if self.context.hasInboundShipment():
return "AnalysisRequestFromShipment"
if self.has_custom_type_registered():
return SAMPLE_FROM_SHIPMENT_ID
return None
42 changes: 42 additions & 0 deletions src/senaite/referral/tests/doctests/IDServer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,45 @@ A new "regular" sample has been created, but with a custom ID:
>>> sample = shipment.getSamples()[0]
>>> api.get_id(sample)
'EXT2-SHIP-01'

However, if no specific portal type has been defined in ID server for samples
from shipments, the system fallback to the default formatting for the
portal type `AnalysisRequest`.

Remove the formatting configuration for the "virtual" type:

>>> bs = portal.bika_setup
>>> records = []
>>> for rec in bs.getIDFormatting():
... if rec["portal_type"] != "AnalysisRequestFromShipment":
... records.append(rec)
>>> bs.setIDFormatting(list(records))

Manually create an inbound shipment:

>>> lab = filter(lambda lab: lab.code == "EXT2", labs)[0]
>>> client = filter(lambda cl: cl.getClientID() == "HH", clients)[0]
>>> values = {
... "referring_laboratory": api.get_uid(lab),
... "referring_client": api.get_uid(client),
... "comments": "Test inbound sample shipment 2",
... "dispatched_datetime": datetime.now() - timedelta(days=2)
... }
>>> shipment = api.create(lab, "InboundSampleShipment", **values)

Create an `InboundSample` object and receive:

>>> values = {
... "referring_id": "000002",
... "date_sampled": datetime.now() - timedelta(days=5),
... "sample_type": "Water",
... "analyses": ["Cu", "Fe"],
... }
>>> inbound_sample = api.create(shipment, "InboundSample", **values)
>>> success = do_action_for(inbound_sample, "receive_inbound_sample")

A new "regular" sample has been created with no special ID:

>>> sample = shipment.getSamples()[0]
>>> api.get_id(sample)
'W-0001'

0 comments on commit 6c2f7f7

Please sign in to comment.