Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix temperature breach filter #2589

Merged
merged 2 commits into from
Dec 8, 2023
Merged

Fix temperature breach filter #2589

merged 2 commits into from
Dec 8, 2023

Conversation

mark-prins
Copy link
Collaborator

Fixes #2537

πŸ‘©πŸ»β€πŸ’» What does this PR do?

Could not repro the stated issue. A related issue was raised in conversation - that the breaches aren't showing.

That's the part which I've addressed here - it turns out that the breach filter was a little over complicated and didn't function as required. The filter was looking for temperature_breach records.. the query was

SELECT "temperature_log"."id", "temperature_log"."temperature", "temperature_log"."sensor_id", "temperature_log"."location_id", "temperature_log"."store_id", "temperature_log"."datetime", "temperature_log"."temperature_breach_id" 
FROM "temperature_log" 
WHERE "temperature_log"."temperature_breach_id" IN 
(SELECT "temperature_breach"."id" FROM "temperature_breach" WHERE "temperature_breach"."id" = 'fff4bac7-2256-43cf-acb9-78acfc8cc7e0') 
ORDER BY "temperature_log"."datetime" DESC

which will not work for new breaches, the breach has to be added before the breach can be added!

I've changed the filter to look for an id only, which simplifies things and allows breaches to be added.

πŸ§ͺ How has/should this change been tested?

Configure a CCA with a sensor and sync with omSupply. get the sensor into a breach and check if the breach shows in oms.

πŸ’Œ Any notes for the reviewer?

πŸ“ƒ Documentation

No user facing changes

@@ -177,6 +177,7 @@ const Chart = ({
borderStyle: 'solid',
borderColor: theme.palette.gray.light,
padding: 3,
textAlign: 'left',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Offroad: the legend was showing with names centred:

Screenshot 2023-12-06 at 10 24 39β€―AM

Copy link

github-actions bot commented Dec 5, 2023

Bundle size difference

Comparing this PR to main

Old size New size Diff
8.28 MB 8.28 MB 158 B (0.00%)

@@ -92,6 +90,9 @@ impl<'a> TemperatureLogRepository<'a> {
query = query.order(temperature_log_dsl::datetime.desc())
}

// Debug diesel query
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just to help with debugging 🀷

@@ -109,7 +109,7 @@ fn validate_sensor(sensor: &Sensor) -> Result<(), String> {
}
match sensor.log_delay {
Some(log_delay) => {
if log_delay < 1 {
if log_delay < 0 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the 'add a debug sensor' function creates a record with 0 here, which meant that the sensor mutation fails for all sensors. since positive number is 0 and up, I figured changing this test still fits the intention

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think technically positive number are greater then zero.

Ohh, what is the add a debug sensor function btw ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in the cold chain app - under developer settings you can add a sensor, and then add random logs for it.

Copy link
Collaborator

@andreievg andreievg left a comment

Choose a reason for hiding this comment

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

@mark-prins.

I haven't tested, but I can't see the difference between the queries, also there is a comment about the breach filter.

The reason I can't see the difference, is there is a referencial contraint on logs, can't set temperature_breach_id, unless the breach exists, so I can't quite see what the difference is between the new filter and the old.

Btw does cold chain app push temperature_logs first or breaches first ? If it's the former then we might have an issue with referencial contraints.

Unforntunately I don't have the cold chain app set up, I wonder if we can share sqlite filter for it, or if there are some postman queries we can use to replicate/validate ?

@@ -42,7 +41,7 @@ pub struct TemperatureLogFilterInput {
pub id: Option<EqualFilterStringInput>,
pub sensor: Option<SensorFilterInput>,
pub location: Option<LocationFilterInput>,
pub temperature_breach: Option<TemperatureBreachFilterInput>,
pub temperature_breach_id: Option<EqualFilterStringInput>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

There was/is a good reason to use this filter.

  • We can re-use existing repository functionality
  • Can filter temperature logs by all of the existing breach filter inputs (type of breach, acknowledge/unacknowledged etc..)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the breach type filter might be broken with this change ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes it does. I searched for any usages of the existing breach filter but didn't spot that..

TemperatureBreachFilter::new().id(EqualFilter::equal_to(&id)),
),
),
Some(TemperatureLogFilter::new().temperature_breach_id(EqualFilter::equal_to(&id))),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I forgot, why do we need to check that there are logs for the breach ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that would be the simplest solution. we just remove the check.
The problem is that the breach doesn't record temperature and we were asked to show 'last temperature reading' in the notification. To do this, it's looking up the log - if the breach exists and the log doesn't then that display breaks. Easy enough to skip that data element - but we do then have strange data, with a breach that has no associated log.

@mark-prins
Copy link
Collaborator Author

Thanks Andrei for review.
I've reverted the filter changes, and removed the log check. Now the api will accept breaches which don't have a log in the database.

To remove any UI strangeness I've added a check in the notification component - if there's no min/max temperature then it just doesn't show. The temperature is also blank in the breach table.

@mark-prins
Copy link
Collaborator Author

Oh, and I'm using postgres, so don't have a sqlite file to share. You can use this postman collection to add a breach or log. I've been using CCA with some sensors that I'm shuttling in and out of the fridge to get it to breach which is a bit of a pain, but it did pick up this particular error that I'd missed earlier.

Cold Chain.postman_collection.json.zip

Copy link
Collaborator

@andreievg andreievg left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for changes @mark-prins.

@mark-prins mark-prins merged commit 80d4bfa into develop Dec 8, 2023
4 checks passed
@mark-prins mark-prins deleted the 2537-breach-not-showing branch December 8, 2023 00:00
@jmbrunskill jmbrunskill mentioned this pull request Jul 31, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cold chain: Temperature logs are not synced from CCA to OMS while a breach is active
2 participants