Skip to content

Commit

Permalink
NiFi scripts: minor updates to cohort export.
Browse files Browse the repository at this point in the history
  • Loading branch information
vladd-bit committed Jul 3, 2024
1 parent 7ef306f commit 80b5c05
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions nifi/user-scripts/cogstack_cohort_generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,30 @@ def _process_patient_records(patient_records: list):
_ptt2sex[_PATIENT_ID] = _tmp_gender

dob = patient_record[PATIENT_BIRTH_DATE_FIELD_NAME] if PATIENT_BIRTH_DATE_FIELD_NAME in patient_record.keys() else 0
dod = patient_record[PATIENT_DEATH_DATE_FIELD_NAME] if PATIENT_DEATH_DATE_FIELD_NAME in patient_record.keys() else None

try:
dob = int(dob)
except ValueError:
dob = str(dob).replace("\"", "").replace("'", "")

try:
dod = int(dod)
except ValueError:
dod = str(dod).replace("\"", "").replace("'", "")

if isinstance(dob, int):
dob = datetime.fromtimestamp(dob / 1000, tz=timezone.utc)
else:
dob = datetime.strptime(str(dob).replace("\"", "").replace("'", ""), DATE_TIME_FORMAT)
dob = datetime.strptime(str(dob), DATE_TIME_FORMAT)

dod = patient_record[PATIENT_DEATH_DATE_FIELD_NAME] if PATIENT_DEATH_DATE_FIELD_NAME in patient_record.keys() else None
patient_age = 0

if dod not in [None, "null", 0]:
if isinstance(dod, int):
dod = datetime.fromtimestamp(dod / 1000, tz=timezone.utc)
else:
dod = datetime.strptime(str(dod).replace("\"", "").replace("'", ""), DATE_TIME_FORMAT)
dod = datetime.strptime(str(dod), DATE_TIME_FORMAT)

patient_age = dod.year - dob.year
else:
Expand Down

0 comments on commit 80b5c05

Please sign in to comment.