OBPIH-6676 Fix binding of inferred lot expiration date#4836
Conversation
|
for bugfixes, if you want the autolabeler to work your branch needs to be |
| return ['inventoryItemNotFound'] | ||
| } | ||
| // Associate inventory item's expiration date with expirationDateToDisplay, to display the date in the table | ||
| item.expirationDateToDisplay = inventoryItem.expirationDate |
There was a problem hiding this comment.
I'll approve the PR because this does seem to fix the issue, but I'm curious why we're setting values like this in the validator. It seems outside of the functionality of what a validator should do
There was a problem hiding this comment.
@ewaterman it's due to the fact, that the expiration date comes from an inventory item, and we do not provide the inventory item's id to be bound, but we rely on product/lotNumber pair that is used to find an inventory item.
The assignment of the expirationDateToDisplay is used only in order to display that date in the table - it is not persisted anywhere and validated.
On regular basis, in the toTableJson() we would just do:
expirationDate: inventoryItem?.expirationDatebut as I wrote earlier - we don't bind the InventoryItem to the ImportPackingListItem, but we rely on product/lotNumber pair.
There was a problem hiding this comment.
it just feels weird for a validation step to be setting any fields on the object, even if they're not persisted. IMO once we hit the validation step, the object should already be fully constructed and so all we should need to do is simple checks on the fields. Embedded validators like this should be small. If we need to do other complex lookups or call other service methods, it signals to me that either we're missing important references in the object, or we might need a more deliberate validation step that happens outside of the object (via a XValidator.validate(x) call or something).
Anyways, the code is already merged and this is not new code, but it does feel to me like this validator is taking on too much responsability.
✨ Description of Change
Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-6676
Description:
There was a case where user provided a non existing binLocation and as a result the expiration date for existing lot was not populated. To fix this issue I just changed the order of the validation and if the inventoryItem existing then bind the expiration date and only after that we validate for bin location
📷 Screenshots & Recordings (optional)