Skip to content

Commit

Permalink
extend /timeline to include questionnaire report data for patient.
Browse files Browse the repository at this point in the history
obtain adherence data if not already in cache on /timeline request
  • Loading branch information
pbugni committed Dec 15, 2023
1 parent 617a1f3 commit ccb6b6e
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions portal/views/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def patient_timeline(patient_id):
from ..models.qbd import QBD
from ..models.qb_status import QB_Status
from ..models.questionnaire_bank import visit_name
from ..models.questionnaire_response import aggregate_responses
from ..models.research_protocol import ResearchProtocol
from ..trace import dump_trace, establish_trace

Expand Down Expand Up @@ -465,17 +466,41 @@ def get_recur_id(qnr):
user, as_of_date=now, research_study_id=EMPRO_RS_ID)
adherence_data = sorted_adherence_data(patient_id, research_study_id)

qnr_responses = aggregate_responses(
instrument_ids=None,
current_user=current_user(),
research_study_id=research_study_id,
patch_dstu2=True,
ignore_qb_requirement=True,
patient_ids=[patient_id]
)
# filter qnr data to a manageable result data set
qnr_data = []
for row in qnr_responses['entry']:
i = {}
d = row['resource']
i['auth_method'] = d['encounter']['auth_method']
i['encounter_period'] = d['encounter']['period']
i['document_authored'] = d['authored']
i['ae_session'] = d['identifier']['value']
i['questionnaire'] = d['questionnaire']['reference'].split('/')[-1]
i['status'] = d['status']
i['org'] = d['subject']['careProvider'][0]['display']
i['visit'] = d['timepoint']
qnr_data.append(i)

kwargs = {
"rps": rps,
"status": status,
"posted": posted,
"timeline": results,
"adherence_data": adherence_data,
"qnr_data": qnr_data
}
if trace:
return jsonify(
rps=rps,
status=status,
posted=posted,
timeline=results,
adherence_data=adherence_data,
trace=dump_trace("END time line lookup"))
return jsonify(
rps=rps, status=status, posted=posted, timeline=results,
adherence_data=adherence_data)
kwargs["trace"] = dump_trace("END time line lookup")

return jsonify(**kwargs)


@patient_api.route('/api/patient/<int:patient_id>/timewarp/<int:days>')
Expand Down

0 comments on commit ccb6b6e

Please sign in to comment.