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
12 changes: 7 additions & 5 deletions nh_eobs/sql_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ def get_workload(self, settings):
when position('notification' in activity.data_model)::bool
then true
else false
end as notification
end as notification,
coalesce(ews0.frequency, 0) as frequency,
coalesce(bg0.frequency, 0) as bg_frequency
from nh_activity activity
inner join nh_activity spell_activity
on spell_activity.id = activity.parent_id
Expand All @@ -379,8 +381,10 @@ def get_workload(self, settings):
on location.id = spell_activity.location_id
inner join nh_clinical_location location_parent
on location_parent.id = location.parent_id
left join ews0 on ews0.spell_activity_id = spell_activity.id
left join ews1 on ews1.spell_activity_id = spell_activity.id
left join ews2 on ews2.spell_activity_id = spell_activity.id
left join bg0 on bg0.spell_activity_id = spell_activity.id
where activity.id in ({activity_ids})
and spell_activity.state = 'started'
order by deadline asc, activity.id desc
Expand Down Expand Up @@ -459,10 +463,8 @@ def get_collect_activities_sql(self, activity_ids_sql):
when ews1.id is not null and ews2.id is null then 'first'
when ews1.id is null and ews2.id is not null then 'no latest'
end as ews_trend,
case
when ews0.frequency is not null then ews0.frequency
else 0
end as frequency,
coalesce(ews0.frequency, 0) as frequency,
coalesce(bg0.frequency, 0) as bg_frequency,
Comment thread
PeterAlabaster marked this conversation as resolved.
spell.custom_frequency,
spell.custom_frequency_reason
from nh_activity activity
Expand Down
48 changes: 47 additions & 1 deletion nh_eobs_mobile/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,16 @@ def get_patients(self, *args, **kw):
cr, uid, patient_api.get_followed_patients(
cr, uid, []), context=context)

for patient in patients:
if patient.get('frequency'):
patient['frequency_string'] = self._convert_frequency_to_string(
patient.get('frequency')
)
if patient.get('bg_frequency'):
patient['bg_frequency_string'] = self._convert_frequency_to_string(
patient.get('bg_frequency')
)

favourites = self.get_user_favourites(uid)

return request.render(
Expand All @@ -590,6 +600,10 @@ def get_patients(self, *args, **kw):
'urls': URLS}
)

@staticmethod
def _convert_frequency_to_string(frequency):
return '{:2d} hour(s) {:02d} min(s)'.format(*divmod(frequency, 60))

@http.route(URLS['escalations'] + '<creator_id>', type='http', auth='user')
def process_escalations(self, creator_id, *args, **kwargs):
"""
Expand Down Expand Up @@ -620,9 +634,16 @@ def process_escalations(self, creator_id, *args, **kwargs):
{
"task_name": activity_detail.display_name,
"task_model": str(activity_detail.data_model),
"task_parent": str(activity_detail.creator_id.data_model),
"frequency": self._get_ews_frequency(
activity_detail.creator_id
),
"bg_frequency": self._get_bg_frequency(
activity_detail.creator_id
),
"activity_id": activity_detail.id,
"task_id": activity_detail.data_ref.id,
"input_fields": self._get_input_field(cr, uid, str(activity_detail.data_model), context=context)
"input_fields": self._get_input_field(cr, uid, str(activity_detail.data_model), context=context),
}
)

Expand All @@ -634,6 +655,21 @@ def process_escalations(self, creator_id, *args, **kwargs):
}
)

def _get_ews_frequency(self, creator_activity):
if creator_activity.data_model == 'nh.clinical.patient.observation.ews':
return self._convert_frequency_to_string(
creator_activity.data_ref.frequency
)
return False

def _get_bg_frequency(self, creator_activity):
if creator_activity.data_model == \
'nh.clinical.patient.observation.blood_glucose':
return self._convert_frequency_to_string(
creator_activity.data_ref.frequency
)
return False

def _get_input_field(self, cr, uid, obj, context=None):
"""
Some escalation tasks require additional data when they are confirmed. This checks the type of task and if
Expand Down Expand Up @@ -868,6 +904,16 @@ def get_tasks(self, *args, **kw):
cr, uid, [], context=context),
context=context)

for task in tasks:
if task.get('frequency'):
task['frequency_string'] = self._convert_frequency_to_string(
task.get('frequency')
)
if task.get('bg_frequency'):
task['bg_frequency_string'] = self._convert_frequency_to_string(
task.get('bg_frequency')
)

favourites = self.get_user_favourites(uid)

return request.render(
Expand Down
2 changes: 1 addition & 1 deletion nh_observations/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def write(self, cr, uid, ids, vals, context=None):
# TODO Is it right that updating the frequency will
# automatically update the date_scheduled to
# create_date + frequency?
date = context.get('effective_date_terminated') \
date = context and context.get('effective_date_terminated') \
or obs.activity_id.creator_id.effective_date_terminated
scheduled = (dt.strptime(
date, DTF)+td(
Expand Down