Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send Welcome Kits by Household #30

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
15 changes: 8 additions & 7 deletions orders/usps_cascadia_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ + "/../../")
Expand Down Expand Up @@ -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:
Expand All @@ -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.')
Expand Down
20 changes: 19 additions & 1 deletion orders/utils/cascadia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -292,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