From e0af2cdc877e055efbc7e12a7e227d6550dfede1 Mon Sep 17 00:00:00 2001 From: Ben Capodanno Date: Wed, 28 Sep 2022 12:30:07 -0700 Subject: [PATCH 1/2] Only Resupply Particpants if They've Received Barcodes A previous version of the resupply function would resupply participants even if they had zero previous swabs assigned to them simply because this zero swabs was below the threshold value. This change makes it explicit that participants should have some number of barcodes before being eligible for a resupply shipment. --- orders/utils/cascadia.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/orders/utils/cascadia.py b/orders/utils/cascadia.py index a08391e..0b225d8 100644 --- a/orders/utils/cascadia.py +++ b/orders/utils/cascadia.py @@ -261,7 +261,8 @@ def household_needs_resupply(house_id, participants, order_report, threshold=3): num_kits = get_participant_kit_count(pt_data) - if num_kits < threshold: + # participant should have some barcodes activated in addition to being below the threshold to trigger a resupply + if num_kits < threshold and any(pt_data['swab_barcodes_complete'] == 2): LOG.debug(f'Participant <{participant}> needs a resupply. Triggering resupply for all participants in household <{house_id}>.') return True From da3d11a3611c19e31bff423c8850356253b104b7 Mon Sep 17 00:00:00 2001 From: Ben Capodanno Date: Wed, 28 Sep 2022 12:32:08 -0700 Subject: [PATCH 2/2] Only Send Welcome Kits if a Household is Fully Consented and Enrolled As the Cascadia study was getting off the ground, we sent welcome kits to a participant if they were fully consented and enrolled even if the household wasn't. Now that the study is further along, this creates additional shipments that we can eliminate. This change only makes a participant eligible for a welcome shipment once their whole household is fully consented and enrolled, even if that participant was consented and enrolled before that. --- orders/usps_cascadia_order.py | 15 ++++++++------- orders/utils/cascadia.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/orders/usps_cascadia_order.py b/orders/usps_cascadia_order.py index 06cefcd..a7980e9 100644 --- a/orders/usps_cascadia_order.py +++ b/orders/usps_cascadia_order.py @@ -3,7 +3,7 @@ import pandas as pd from utils.redcap import init_project, get_redcap_report, get_cascadia_study_pause_reports from utils.common import USPS_EXPORT_COLS, LOGISTICS_S3_BUCKET, LOGISTICS_USPS_PATH, export_orders -from utils.cascadia import append_order, get_household_address, participant_under_study_pause, household_needs_resupply, get_participant_kit_count +from utils.cascadia import append_order, get_household_address, participant_under_study_pause, household_needs_resupply, household_fully_consented_and_enrolled, get_participant_kit_count # Place all modules within this script's path BASE_DIR = os.path.abspath(__file__ + "/../../") @@ -52,6 +52,7 @@ def main(args): # first need to check if any participants in a househould need a resupply. If they do, we will # be resupplying ALL participants in the househould, even if they don't necessarily need it. needs_resupply = household_needs_resupply(house_id, participants, order_report, threshold=3) + hh_fully_consented = household_fully_consented_and_enrolled(house_id, participants, order_report) LOG.debug(f'Resupply is set to <{needs_resupply}> for household <{house_id}>.') for participant in participants: @@ -63,16 +64,16 @@ def main(args): LOG.debug(f'Participant <{participant}> must be consented and enrolled to receive swab kits.') continue - # if no swab barcodes have been completed they need a welcome kit and won't need anything else - if not any(pt_data['swab_barcodes_complete'] == 2): - LOG.debug(f'Participant <{participant}> has no complete swabs. Adding a welcome kit to their inventory.') - kits_needed['welcome'][participant] = 1 - continue - if participant_under_study_pause(pause_report, house_id, participant): LOG.info(f'Participant <{participant}> from household <{house_id}> is under study pause. Deliveries are stopped until the pause end date.') continue + # if no swab barcodes have been completed and the household is fully enrolled + consented they need a welcome kit and won't need anything else + if hh_fully_consented and not any(pt_data['swab_barcodes_complete'] == 2): + LOG.debug(f'Adding a welcome kit to participant <{participant}> inventory as household <{house_id}> is fully consented + enrolled.') + kits_needed['welcome'][participant] = 1 + continue + if needs_resupply: num_kits = get_participant_kit_count(pt_data) LOG.debug(f'Participant has total {num_kits} usable kits.') diff --git a/orders/utils/cascadia.py b/orders/utils/cascadia.py index 0b225d8..e2e10af 100644 --- a/orders/utils/cascadia.py +++ b/orders/utils/cascadia.py @@ -293,3 +293,20 @@ def get_yesterdays_orders(orders): LOG.info(f'Filtering orders to those requested on <{yesterday.strftime("%m-%d-%Y")}>.') return orders[orders['Order Date'] == yesterday.strftime('%m-%d-%Y')] + + +def household_fully_consented_and_enrolled(house_id, participants, order_report): + """ + Check if any participant in a household is in need of a resupply. This is true if they + have less kits than the passed threshold number. + """ + + for participant in participants: + pt_data = order_report.loc[[(house_id, participant)]] + + if not (any(pt_data['enrollment_survey_complete'] == 2) and any(pt_data['consent_form_complete'] == 2)): + LOG.debug(f'Participant <{participant}> must be consented and enrolled for household <{house_id}> to be fully consented and enrolled.') + return False + + LOG.debug(f'All participants in household <{house_id}> are consented and enrolled.') + return True