Skip to content
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
18 changes: 10 additions & 8 deletions nh_food_and_fluid/models/food_and_fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ def get_period_domain(self, date_time):
period_start_datetime_str = self.get_period_start_datetime(date_time)
period_end_datetime_str = self.get_period_end_datetime(date_time)
domain = [
('date_terminated', '>=', period_start_datetime_str),
('date_terminated', '<', period_end_datetime_str)
('effective_date_terminated', '>=', period_start_datetime_str),
('effective_date_terminated', '<', period_end_datetime_str)
]
return domain

Expand Down Expand Up @@ -508,7 +508,7 @@ def get_all_completed_food_and_fluid_observation_activities(
('spell_activity_id', '=', spell_activity_id)
]
obs_activities = activity_model.search(domain,
order='date_terminated asc')
order='effective_date_terminated asc')
return obs_activities

@api.multi
Expand Down Expand Up @@ -566,8 +566,9 @@ def get_period_dictionaries(self, food_and_fluid_observations,
# periods containing their observations.
for obs in food_and_fluid_observations:
date_terminated = obs['date_terminated']
effective_date_terminated = obs['effective_date_terminated']
period_start_datetime = \
food_and_fluid_model.get_period_start_datetime(date_terminated)
food_and_fluid_model.get_period_start_datetime(effective_date_terminated)
# If this observation is the first in a new period,
# add the new period to the list.
if period_start_datetime != period_start_datetime_current:
Expand Down Expand Up @@ -605,23 +606,24 @@ def _create_new_period_dictionary(self, obs, spell_activity_id,

# Set period start and end datetimes.
date_terminated = obs['date_terminated']
effective_date_terminated = obs['effective_date_terminated']
period['period_start_datetime'] = \
food_and_fluid_model.get_period_start_datetime(date_terminated)
food_and_fluid_model.get_period_start_datetime(effective_date_terminated)
period['period_end_datetime'] = \
food_and_fluid_model.get_period_end_datetime(date_terminated)
food_and_fluid_model.get_period_end_datetime(effective_date_terminated)

# Set fluid intake.
total_fluid_intake = \
food_and_fluid_model.calculate_total_fluid_intake(
spell_activity_id, date_terminated
spell_activity_id, effective_date_terminated
)
if include_units:
total_fluid_intake = "{}ml".format(total_fluid_intake)
period['total_fluid_intake'] = total_fluid_intake

# Set fluid balance.
fluid_balance = self.calculate_fluid_balance(spell_activity_id,
date_terminated)
effective_date_terminated)
if include_units:
fluid_balance = \
self.format_fluid_balance_for_frontend(fluid_balance)
Expand Down
11 changes: 7 additions & 4 deletions nh_food_and_fluid/static/src/js/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ var fluidTableDescription = {
};

function drawFood_fluidTable(settings, serverData){
serverData.sort(function (a, b) {
var dateA = new Date(a.effective_date_terminated).getTime(), dateB = new Date(b.effective_date_terminated).getTime();
return dateA - dateB;
});
for ( var idx = 0; idx < serverData.length; idx++ ) {
var data = serverData[idx];
data.observations.sort( function (a, b) {
Copy link
Copy Markdown
Contributor

@PeterAlabaster PeterAlabaster Jul 30, 2020

Choose a reason for hiding this comment

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

Does this not require re-assigning (data.observations = data.observations.sort(....) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not this time. sort() changes inline rather than assigns to a new array.

var dateA = new Date(a.effective_date_terminated).getTime(), dateB = new Date(b.effective_date_terminated).getTime();
return dateB - dateA;
})
}
setUpControls();
var processedData = processFoodFluidData(serverData);
if(!settings.desktop){
Expand Down