Skip to content
Merged
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
1 change: 0 additions & 1 deletion claims_hosp/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ disable=logging-format-interpolation,
no-self-use,
# Allow pytest classes to have one test.
too-few-public-methods,
broad-except


[BASIC]
Expand Down
24 changes: 10 additions & 14 deletions claims_hosp/delphi_claims_hosp/download_claims_ftp_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
import functools
from os import path
import re

# third party
import paramiko
Expand All @@ -24,19 +25,13 @@ def print_callback(filename, logger, bytes_so_far, bytes_total):
if (rough_percent_transferred % 25) == 0:
logger.info("Transfer in progress", filename=filename, percent=rough_percent_transferred)


FILENAME_TIMESTAMP = re.compile(r".*EDI_AGG_INPATIENT_(?P<ymd>[0-9]*)_(?P<hm>[0-9]*)[^0-9]*")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to check with

FILENAME_TIMESTAMP = re.compile(r".*EDI_AGG_(.*?)PATIENT_(?P<ymd>[0-9]*)_(?P<hm>[0-9]*)[^0-9]*")

since we consider the number of all the files available in the hosp/receiving dir but not just INPATIENT files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does claims_hosp need the outpatient files as well? Or are those processed by doctor-visits instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR don't use outpatient files. But the code does check the number of all the files available. I am not sure why Maria design it in this way. If we don't check the inpatient files here, it's better to also update the assertion statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to also update the assertion statement

done

def get_timestamp(name):
"""Get the reference date in datetime format."""
try:
split_name = name.split("_")
yyyymmdd = split_name[3]
hhmm = ''.join(filter(str.isdigit, split_name[4]))
timestamp = datetime.datetime.strptime(''.join([yyyymmdd, hhmm]),
"%Y%m%d%H%M")
except Exception:
timestamp = datetime.datetime(1900, 1, 1)

return timestamp
m = FILENAME_TIMESTAMP.match(name)
if not m:
return datetime.datetime(1900, 1, 1)
return datetime.datetime.strptime(''.join(m.groups()), "%Y%m%d%H%M")

def change_date_format(name):
"""Flip date from YYYYMMDD to MMDDYYYY."""
Expand Down Expand Up @@ -75,9 +70,10 @@ def download(ftp_credentials, out_path, logger):
files_to_download.append(fileattr.filename)
logger.info("File to download", filename=fileattr.filename)

# make sure we don't download more that the 3 chunked drops (2x a day) for OP
# and the 1 chunk (2x a day) for IP - 01/07/21, *2 for multiple day drops
assert len(files_to_download) <= 2 * ((3 * 2) + 2), "more files dropped than expected"
# make sure we don't download more than the 1 chunk (2x a day) drops for IP - 01/07/21,
# *2 for multiple day drops
assert len(files_to_download) <= 2 * (2), \
f"more files dropped ({len(files_to_download)}) than expected (4)"

filepaths_to_download = {}
for file in files_to_download:
Expand Down