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
3 changes: 2 additions & 1 deletion nh_eobs/sql_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ def get_collect_activities_sql(self, activity_ids_sql):
case
when ews0.frequency is not null then ews0.frequency
else 0
end as frequency
end as frequency,
spell.custom_frequency
from nh_activity activity
inner join nh_clinical_patient patient
on patient.id = activity.patient_id
Expand Down
33 changes: 33 additions & 0 deletions nh_eobs_mobile/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,40 @@ def _update_effective_date():
effective_date = record.activity_id.creator_id.effective_date_terminated
vals.update({'effective_date_terminated': effective_date})

def _check_if_custom_frequency():

def _find_next_ews_obs(patient_id):
activity_data_ids = obj_nh_activity.search(cr, uid, [
('state', 'not in', ['completed', 'cancelled']),
('data_model', '=', 'nh.clinical.patient.observation.ews'),
('patient_id', '=', patient_id)
], context=context)
if len(activity_data_ids) == 1:
return obj_nh_activity.browse(cr, uid, activity_data_ids, context=context)

for k, v in kwargs.items():
try:
data_id = int(v)
data_model = request.registry[k]
activity = data_model.browse(cr, uid, data_id, context=context)
patient = activity.patient_id
obj_nh_clinical_spell = request.registry['nh.clinical.spell']
current_spell_id = obj_nh_clinical_spell.search(cr, uid, [
('patient_id', '=', patient.id),
('state', '=', 'started')
], context=context)
current_spell = obj_nh_clinical_spell.browse(cr, uid, current_spell_id, context=context)
if current_spell.custom_frequency:
next_ews_obs_activity = _find_next_ews_obs(patient.id)
next_ews_obs_activity.data_ref.write({'frequency': current_spell.custom_frequency})
request.cr.execute("""refresh materialized view ews0;""")
break
except ValueError:
pass

cr, uid, context = request.cr, request.session.uid, request.context
obj_nh_activity = request.registry['nh.activity']

for key, val in kwargs.items():
try:
int(key)
Expand Down Expand Up @@ -730,6 +762,7 @@ def _update_effective_date():
cr.execute('refresh materialized view ews0;\n')
obj_model.write(cr, uid, record_id, vals)

_check_if_custom_frequency()
return self.get_tasks()

@http.route(URLS['all_patients'], type='http', auth="user")
Expand Down
6 changes: 6 additions & 0 deletions nh_observations/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# TODO EOBS-840: Make frequencies.py a model and split it across modules as
# appropriate.
# Frequencies in minutes.
FIVE_MINUTES = 5
TEN_MINUTES = 10
FIFTEEN_MINUTES = 15
THIRTY_MINUTES = 30
ONE_HOUR = 60
Expand All @@ -19,6 +21,8 @@
ONE_WEEK = 10080

# Tuples with the time and a label.
EVERY_5_MINUTES = (FIVE_MINUTES, 'Every 5 Minutes')
EVERY_10_MINUTES = (TEN_MINUTES, 'Every 10 Minutes')
EVERY_15_MINUTES = (FIFTEEN_MINUTES, 'Every 15 Minutes')
EVERY_30_MINUTES = (THIRTY_MINUTES, 'Every 30 Minutes')
EVERY_HOUR = (ONE_HOUR, 'Every Hour')
Expand All @@ -34,6 +38,8 @@

# Dictionary to lookup tuples by frequency in minutes.
ALL_FREQUENCIES = {
FIVE_MINUTES: EVERY_5_MINUTES,
TEN_MINUTES: EVERY_10_MINUTES,
FIFTEEN_MINUTES: EVERY_15_MINUTES,
THIRTY_MINUTES: EVERY_30_MINUTES,
ONE_HOUR: EVERY_HOUR,
Expand Down