Skip to content

Commit

Permalink
hotfix postevent summary dashboard where calculating prod data causes…
Browse files Browse the repository at this point in the history
… error (#90)

Problem
The postvent summary dashboard was getting incomplete (null) data from
the db. This was causing the dashboard to throw an error when trying to calculate the data for the dashboard.

Solution
- Update dev seeder to generate incomplete data for the postevent summary dashboard
to reproduce the error
- Add checks to the postevent summary dashboard to handle incomplete data

Ticket URL
N/A

Documentation
N/A

Tests Run
- locally ran `yarn build`. No errors
- Navigated in local dev environment to the postevent summary dashboard
    + `http://localhost:3000/medical/dashboards/postevent-summary`
    + The dashboard calculates without errors
  • Loading branch information
critch646 authored Feb 7, 2024
1 parent 64904a8 commit af22308
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
9 changes: 9 additions & 0 deletions app/api/seeder/generate_patient_encounters.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ def generate_dates_and_times(
# Generate a random arrival datetime within the given range
arrival_date_time = fake.date_time_between(start_date=start_date, end_date=end_date)

# 5% chance no departure date and time
if random.random() < 0.05:
return {
"arrival_date": arrival_date_time.date(),
"arrival_time": arrival_date_time.time(),
"departure_date": None,
"departure_time": None,
}

# Define length of stay based on triage_acuity
if triage_acuity == "white":
length_of_stay = timedelta(minutes=10)
Expand Down
16 changes: 11 additions & 5 deletions app/api/seeder/seed_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,18 @@ def seed_database():
arrival_datetime = datetime.combine(
patient_encounter["arrival_date"], patient_encounter["arrival_time"]
)
departure_datetime = datetime.combine(
patient_encounter["departure_date"], patient_encounter["departure_time"]
)

patient_encounter["arrival_time"] = arrival_datetime
patient_encounter["departure_time"] = departure_datetime

if (
patient_encounter["departure_date"] is not None
and patient_encounter["departure_time"] is not None
):
departure_datetime = datetime.combine(
patient_encounter["departure_date"], patient_encounter["departure_time"]
)
patient_encounter["departure_time"] = departure_datetime
else:
patient_encounter["departure_time"] = None

# Create patient encounter
patient_encounter_obj = PatientEncounter(**patient_encounter)
Expand Down
17 changes: 15 additions & 2 deletions app/web/utils/postfestivalDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ export function calculatePostFestivalLengthOfStayData(
];

const losDurations = patientEncounters.map((encounter) => {
if (
encounter.departure_date === null ||
encounter.departure_time === null
) {
console.log("DEBUG: RETURNING NULL");
return { durationMinutes: null, acuity: encounter.triage_acuity };
}

const arrivalDateTime = new Date(encounter.arrival_date);
arrivalDateTime.setHours(encounter.arrival_time.getHours());
arrivalDateTime.setMinutes(encounter.arrival_time.getMinutes());
Expand All @@ -284,7 +292,9 @@ export function calculatePostFestivalLengthOfStayData(

losDurations.forEach(({ durationMinutes, acuity }) => {
let rowIndex;
if (durationMinutes <= 15) {
if (durationMinutes === null) {
rowIndex = 0;
} else if (durationMinutes <= 15) {
rowIndex = 1;
} else if (durationMinutes <= 30) {
rowIndex = 2;
Expand All @@ -310,7 +320,6 @@ export function calculatePostFestivalLengthOfStayData(

(rowsDataCCCount[rowIndex][1] as number)++;

console.log("acuity", acuity);
// Increment the count for the specific triage acuity
switch (acuity) {
case TriageAcuities.Red:
Expand All @@ -336,6 +345,10 @@ export function calculatePostFestivalLengthOfStayData(
const whiteDurations: number[] = [];

losDurations.forEach(({ durationMinutes, acuity }) => {
if (durationMinutes === null) {
return;
}

totalDurations.push(durationMinutes);
switch (acuity) {
case TriageAcuities.Red:
Expand Down

0 comments on commit af22308

Please sign in to comment.