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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions client/packages/coldchain/src/ColdchainNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ export const ColdchainNotification = () => {
</b>
</Text>
<Separator />
<Text>
{t('message.last-temperature', {
temperature: breach.maxOrMinTemperature,
})}
</Text>
<Separator />
{!!breach.maxOrMinTemperature && (
<>
<Text>
{t('message.last-temperature', {
temperature: breach.maxOrMinTemperature,
})}
</Text>
<Separator />
</>
)}
<Text>
{t('message.device')}
<b style={{ paddingLeft: 4 }}>{breach.sensor?.name}</b>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

}}
>
<svg
Expand Down
30 changes: 30 additions & 0 deletions client/packages/common/src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3754,6 +3754,7 @@ export type Queries = {
syncSettings?: Maybe<SyncSettingsNode>;
/** Query omSupply "temperature_breach" entries */
temperatureBreaches: TemperatureBreachesResponse;
temperatureChart: TemperatureChartResponse;
/** Query omSupply "temperature_log" entries */
temperatureLogs: TemperatureLogsResponse;
};
Expand Down Expand Up @@ -4153,6 +4154,15 @@ export type QueriesTemperatureBreachesArgs = {
};


export type QueriesTemperatureChartArgs = {
filter?: InputMaybe<TemperatureLogFilterInput>;
fromDatetime: Scalars['DateTime']['input'];
numberOfDataPoints: Scalars['Int']['input'];
storeId: Scalars['String']['input'];
toDatetime: Scalars['DateTime']['input'];
};


export type QueriesTemperatureLogsArgs = {
filter?: InputMaybe<TemperatureLogFilterInput>;
page?: InputMaybe<PaginationInput>;
Expand Down Expand Up @@ -4526,6 +4536,12 @@ export type ResponseStoreStatsNode = {
stockOnOrder: Scalars['Int']['output'];
};

export type SensorAxisNode = {
__typename: 'SensorAxisNode';
points: Array<TemperaturePointNode>;
sensor?: Maybe<SensorNode>;
};

export type SensorConnector = {
__typename: 'SensorConnector';
nodes: Array<SensorNode>;
Expand Down Expand Up @@ -5038,6 +5054,13 @@ export type TemperatureBreachSortInput = {

export type TemperatureBreachesResponse = TemperatureBreachConnector;

export type TemperatureChartNode = {
__typename: 'TemperatureChartNode';
sensors: Array<SensorAxisNode>;
};

export type TemperatureChartResponse = TemperatureChartNode;

export type TemperatureLogConnector = {
__typename: 'TemperatureLogConnector';
nodes: Array<TemperatureLogNode>;
Expand Down Expand Up @@ -5080,6 +5103,13 @@ export type TemperatureLogSortInput = {

export type TemperatureLogsResponse = TemperatureLogConnector;

export type TemperaturePointNode = {
__typename: 'TemperaturePointNode';
breachIds?: Maybe<Array<Scalars['String']['output']>>;
midPoint: Scalars['DateTime']['output'];
temperature?: Maybe<Scalars['Float']['output']>;
};

export type TokenExpired = RefreshTokenErrorInterface & {
__typename: 'TokenExpired';
description: Scalars['String']['output'];
Expand Down
4 changes: 3 additions & 1 deletion server/repository/src/db_diesel/temperature_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,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 🀷

// println!("{}", diesel::debug_query::<DBType, _>(&query).to_string());

let result = query
.offset(pagination.offset as i64)
.limit(pagination.limit as i64)
Expand Down Expand Up @@ -128,7 +131,6 @@ impl<'a> TemperatureLogRepository<'a> {
.select(location_dsl::id.nullable());
query = query.filter(temperature_log_dsl::location_id.eq_any(location_ids));
}

if temperature_breach.is_some() {
let temperature_breach_ids =
TemperatureBreachRepository::create_filtered_query(temperature_breach)
Expand Down
2 changes: 1 addition & 1 deletion server/server/src/cold_chain/sensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

return Err(format!(" {}: Log delay must be positive", sensor.id));
}
}
Expand Down
27 changes: 1 addition & 26 deletions server/server/src/cold_chain/temperature_breach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use anyhow::Context;
use chrono::NaiveDateTime;
use log::error;
use mime_guess::mime;
use repository::{
EqualFilter, RepositoryError, TemperatureBreachFilter, TemperatureBreachRowType,
TemperatureLogFilter,
};
use repository::{RepositoryError, TemperatureBreachRowType};
use service::{
auth_data::AuthData,
service_provider::{ServiceContext, ServiceProvider},
Expand Down Expand Up @@ -120,28 +117,6 @@ fn upsert_temperature_breach(
let id = breach.id.clone();
let service = &service_provider.temperature_breach_service;
let sensor_service = &service_provider.sensor_service;
let log_service = &service_provider.temperature_log_service;

if log_service
.get_temperature_logs(
&ctx.connection,
None,
Some(
TemperatureLogFilter::new().temperature_breach(
TemperatureBreachFilter::new().id(EqualFilter::equal_to(&id)),
),
),
None,
)
.map_err(|e| anyhow::anyhow!("Unable to load logs for this breach {:?}", e))?
.count
== 0
{
return Err(anyhow::anyhow!(
"No temperature logs found for the breach id `{}`",
id
));
}

let sensor = sensor_service
.get_sensor(&ctx, breach.sensor_id.clone())
Expand Down
Loading