Skip to content

Commit

Permalink
Use survey timestamps for uw-reopening collection date
Browse files Browse the repository at this point in the history
Favor the survey timestamps over custom date fields.
  • Loading branch information
Chris Craft committed Jan 8, 2021
1 parent ce745a5 commit 72b70ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/seattleflu/id3c/cli/command/etl/redcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .redcap_map import map_sex, map_symptom, UnknownVaccineResponseError
from id3c.cli.command.geocode import get_geocoded_address
from id3c.cli.command.location import location_lookup
from id3c.cli.redcap import Record as REDCapRecord
from id3c.cli.redcap import is_complete, Record as REDCapRecord
from id3c.db.session import DatabaseSession
import logging

Expand Down Expand Up @@ -697,7 +697,7 @@ def extract_date_from_survey_timestamp(record: REDCapRecord, survey_name: str) -
is in local (Pacific) time. The timestamp will be populated only if the instrument was filled out
as a survey. The timestamp field cannot be set via a REDCap data import.
"""
if record and survey_name and record.get(f'{survey_name}_timestamp'):
if record and survey_name and is_complete(survey_name, record) and record.get(f'{survey_name}_timestamp'):
return datetime.strptime(record.get(f'{survey_name}_timestamp'),
'%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d')

Expand Down
20 changes: 15 additions & 5 deletions lib/seattleflu/id3c/cli/command/etl/redcap_det_uw_reopening.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,26 @@ def create_encounter_id(record: REDCapRecord, is_followup_encounter: bool) -> st
f'{redcap_repeat_instance}{encounter_identifier_suffix}'


def get_collection_date(record: dict, collection_method: CollectionMethod) -> Optional[str]:
def get_collection_date(record: REDCapRecord, collection_method: CollectionMethod) -> Optional[str]:
"""
Determine sample/specimen collection date from the given REDCap *record*.
"""
# For all surveys, try the survey _timestamp field (which is in Pacific time)
# before custom fields because the custom fields aren't always populated and when
# they are populated they use the browser's time zone.
collection_date = None

if collection_method == CollectionMethod.KIOSK:
return record["nasal_swab_q"]
collection_date = extract_date_from_survey_timestamp(record, "kiosk_registration_4c7f") or record.get("nasal_swab_q")

elif collection_method == CollectionMethod.SWAB_AND_SEND:
return record["date_on_tube"] or record["kit_reg_date"] or record["back_end_scan_date"]
else:
return None
collection_date = record.get("date_on_tube") \
or extract_date_from_survey_timestamp(record, "husky_test_kit_registration") \
or record.get("kit_reg_date") \
or extract_date_from_survey_timestamp(record, "test_fulfillment_form") \
or record.get("back_end_scan_date")

return collection_date


def create_enrollment_questionnaire_response(record: REDCapRecord, patient_reference: dict,
Expand Down

0 comments on commit 72b70ea

Please sign in to comment.