Skip to content

Commit

Permalink
refactor: get_latest_trace and update_context_with_counts now get the…
Browse files Browse the repository at this point in the history
… pj name themself
  • Loading branch information
thangixd committed May 23, 2024
1 parent 8fe26d6 commit b5de21c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tracex_project/db_results/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,25 @@ def get_context_data(self, **kwargs):
"""

context = super().get_context_data(**kwargs)
patient_journey_name = self.request.session["patient_journey_name"]
trace_df = self.get_latest_trace_df(patient_journey_name)
trace_df = self.get_latest_trace_df()

self.update_context_with_counts(context, trace_df, patient_journey_name)
self.update_context_with_counts(context, trace_df)
self.update_context_with_charts(context, trace_df)
self.update_context_with_data_tables(context, trace_df)

return context

def get_latest_trace_df(self, patient_journey_name):
def get_latest_trace_df(self):
"""
Fetch the DataFrame for the latest trace of a specific patient journey.
Fetch the DataFrame for the latest trace of a specific patient journey stored in the session.
This method constructs a query to fetch the ID of the latest trace entry related to a given
This method constructs a query to fetch the ID of the latest trace entry related to a
patient journey. It considers only those entries where activity relevance, timestamp correctness,
and correctness confidence metrics are not null. It then retrieves the DataFrame for these
events.
"""
patient_journey_name = self.request.session["patient_journey_name"]

query_last_trace = Q(
id=Trace.manager.filter(
patient_journey__name=patient_journey_name,
Expand All @@ -87,8 +88,10 @@ def get_latest_trace_df(self, patient_journey_name):
)
return u.DataFrameUtilities.get_events_df(query_last_trace)

def update_context_with_counts(self, context, trace_df, patient_journey_name):
def update_context_with_counts(self, context, trace_df):
"""Update the given context dictionary with count statistics related to patient journeys and traces."""
patient_journey_name = self.request.session["patient_journey_name"]

context.update({
"patient_journey_name": patient_journey_name,
"total_patient_journeys": PatientJourney.manager.count(),
Expand Down

0 comments on commit b5de21c

Please sign in to comment.