Skip to content

Commit

Permalink
NiFi: updated cohort script to autocomplete missing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
vladd-bit committed Feb 21, 2024
1 parent 700e91c commit 04fe563
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions nifi/user-scripts/cogstack_cohort_generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ def dict2json_file(input_dict, fn):

for patient_record in input_patient_record_data:

_ethnicity = str(patient_record[PATIENT_ETHNICITY_FIELD_NAME]).lower().replace("-", " ").replace("_", " ")
_ethnicity = str(patient_record[PATIENT_ETHNICITY_FIELD_NAME]).lower().replace("-", " ").replace("_", " ") if PATIENT_ETHNICITY_FIELD_NAME in patient_record.keys() else "other"

if _ethnicity in ethnicity_map.keys():
ptt2eth[patient_record[PATIENT_ID_FIELD_NAME]] = ethnicity_map[_ethnicity].title()
else:
ptt2eth[patient_record[PATIENT_ID_FIELD_NAME]] = _ethnicity.title()

# based on: https://www.datadictionary.nhs.uk/attributes/person_gender_code.html
_tmp_gender = str(patient_record[PATIENT_GENDER_FIELD_NAME]).lower()
_tmp_gender = str(patient_record[PATIENT_GENDER_FIELD_NAME]).lower() if PATIENT_GENDER_FIELD_NAME in patient_record.keys() else "Unknown"
if _tmp_gender in ["male", "1", "m"]:
_tmp_gender = "Male"
elif _tmp_gender in ["female", "2", "f"]:
Expand All @@ -100,10 +100,10 @@ def dict2json_file(input_dict, fn):

dob = datetime.strptime(patient_record[PATIENT_BIRTH_DATE_FIELD_NAME], DATE_TIME_FORMAT)

dod = patient_record[PATIENT_DEATH_DATE_FIELD_NAME]
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"]:
if dod not in [None, "null", 0]:
dod = datetime.strptime(patient_record[PATIENT_DEATH_DATE_FIELD_NAME], DATE_TIME_FORMAT)
patient_age = dod.year - dob.year
else:
Expand Down

0 comments on commit 04fe563

Please sign in to comment.