Skip to content

OBPIH-7101 fix unique expiration date validation#5143

Merged
awalkowiak merged 2 commits intodevelopfrom
bug/OBPIH-7101-cycle-count-expiration-date-validation
Mar 20, 2025
Merged

OBPIH-7101 fix unique expiration date validation#5143
awalkowiak merged 2 commits intodevelopfrom
bug/OBPIH-7101-cycle-count-expiration-date-validation

Conversation

@ewaterman
Copy link
Member

@ewaterman ewaterman commented Mar 17, 2025

✨ Description of Change

Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-7101

Description: The specific issue brought up here is triggered when an existing (non-custom) row has an expiry and you try to add a new, custom row for the same lot and expiry. The error is caused by the fact that InventoryItems use a custom date format which the frontend doesn't use when adding new rows.

InventoryItem.groovy:

Map toJson() {
    [
        ...
        "expirationDate" : expirationDate?.format("MM/dd/yyyy"),
        ...
    ]
}

So when we’re validating in useInventoryValidation.checkDifferentExpirationDatesForTheSameLot, we get rows that have the same date but in different formats, so it thinks they’re different and throws a validation error:

"03/03/2027"                 -> existing row returned from the backend
"2027-03-03T17:00:00-08:00"  -> custom row not yet persisted to the backend

📷 Screenshots & Recordings (optional)

image

@github-actions github-actions bot added type: bug Addresses unintended behaviours of the app domain: frontend Changes or discussions relating to the frontend UI labels Mar 17, 2025
@ewaterman ewaterman added the warn: do not merge Marks a pull request that is not yet ready to be merged label Mar 17, 2025
const expirationDate = item?.inventoryItem?.expirationDate;
// TODO: isSame is returning false, even if the dates are the same! I suspect it's trying
// to use local time when parsing "MM/dd/yyyy". Gotta find a way to make this default
// to UTC. This kinda sucks though, maybe we need a more general solution to this...
Copy link
Member Author

@ewaterman ewaterman Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would appreciate anyone's help getting this to work cleanly.

I'm sure there's a way to treat the string as UTC by default (for the "MM/dd/yyyy" case) but then also if the string has timezone specified, use that (for the "yyyy-MM-dd'T'hh:mm:ssXXX" case). I'm just slow to figure out how to do stuff on the frontend.

That said, a part of me feels like the best solution is to modify the cycle count logic on the frontend to always work in the "MM/dd/yyyy" format for expiration dates (we can still display "dd/MMM/yyyy"). The inconsistency here is really awkward to work around. I don't see exactly where on the frontend the disconnect is happening though so I don't know where it's setting the "yyyy-MM-dd'T'hh:mm:ssXXX" format

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we can't just trim off the time portion of the date/moment because it could result in the date being different.

Ex: 2000-01-01T00:00:00Z == 1999-12-31T23:00:00-01:00 so we need to be careful about how we handle this. It's why just working with MM/dd/yyyy is probably simplest. No time component at all to work with...

@ewaterman ewaterman self-assigned this Mar 17, 2025
@codecov
Copy link

codecov bot commented Mar 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 8.15%. Comparing base (1d26a5c) to head (016cbc0).
Report is 164 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff              @@
##             develop   #5143      +/-   ##
============================================
- Coverage       8.15%   8.15%   -0.01%     
  Complexity       945     945              
============================================
  Files            637     637              
  Lines          43133   43134       +1     
  Branches       10486   10486              
============================================
  Hits            3517    3517              
- Misses         39077   39078       +1     
  Partials         539     539              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ewaterman ewaterman changed the title WIP: fix unique expiration date validation OBPIH-7101 fix unique expiration date validation Mar 17, 2025
Comment on lines 56 to 58
return expirationDate == null ? null : moment(expirationDate);
});
const uniqueDates = _.uniqWith(expirationDates, (arrVal, othVal) => arrVal?.isSame(othVal));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can try to use .format on the moment date, and then put those in _.uniq

Copy link
Member Author

@ewaterman ewaterman Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was doing something like that originally. It doesn't work either way because the moments are different.

Interestingly. the first time I pick a date using the datepicker, it always picks the day before I select. Then if I try again, it works. Maybe something to do with DateField.jsx? Not sure if that's related. https://jam.dev/c/7765ce91-6ee6-4c45-a5e0-978a6a54e38e

If I do something like this:

image

I end up with these expiration date strings being parsed in:

existing item (bin "Ph: Med Equip & Supplies")
- inventory item: "03/03/2027"
- moment as iso string: "2027-03-03T08:00:00.000Z"   -> is it converting to my local time but thinking it's still UTC?? I'm UTC -8
- moment formatted as date: "03/03/2027"

new item, first time click March 3rd, 2027 (it actually picks the 2nd)
- inventory item: "2027-03-03T00:00:00Z"
- moment as iso string: "2027-03-03T00:00:00.000Z"
- monent formatted as date: "03/02/2027"

new item, second time click March 3rd, 2027 (it properly picks the 3rd)
- inventory item: "2027-03-03T16:00:00-08:00"  -> this converts to my local time but it's the 4th??
- moment as iso string: "2027-03-04T00:00:00.000Z" 
- moment formatted as date: "03/03/2027"

So they don't always resolve to the same day, despite appearing as if they are. I don't actually know exactly what is happening to cause the dates to be different. My best guess is it tries to parse "03/03/2027" using system local time instead of UTC.

Copy link
Member Author

@ewaterman ewaterman Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the first issue by defaulting to utc when parsing the string to a moment. The second issue (with the picker selecting the day before) is less obvious of a fix. I'm going to make a separate ticket to track that one though so this PR is ready for review as is.

EDIT: created https://pihemr.atlassian.net/browse/OBPIH-7114 to track the other issue

@ewaterman ewaterman removed the warn: do not merge Marks a pull request that is not yet ready to be merged label Mar 18, 2025
@awalkowiak awalkowiak merged commit 180abd5 into develop Mar 20, 2025
9 checks passed
@awalkowiak awalkowiak deleted the bug/OBPIH-7101-cycle-count-expiration-date-validation branch March 20, 2025 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: frontend Changes or discussions relating to the frontend UI type: bug Addresses unintended behaviours of the app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants