def gen_patients(): """ # Read data from file and create patient and event object line by line """ patients = {} with open(PATIENT_DATA, 'rb') as f: reader = csv.reader(f, delimiter="|") next(reader, None) for row in reader: patient = new_patient(row) if patient: patients[row[0]] = patient logger.info("Loaded patients data") with open(EVENT_DATA, 'rb') as f: reader = csv.reader(f, delimiter="|") next(reader, None) for row in reader: p_id = row[0] event = new_event(row) if event and p_id in patients: # if it's a valid event and it has a matching patient patients[p_id].add_event(event) logger.info("Loaded events data") return patients
def patient_a(): patient_a = new_patient(("id-771", "1981-12-20", "F")) patient_a.add_event(new_event(("id-771", "2003-09-24", "10", "t023.0"))) patient_a.add_event(new_event(("id-771", "2015-09-21", "9", "367.0"))) patient_a.add_event(new_event(("id-771", "2018-03-23", "10", "z23.0"))) patient_a.add_event(new_event(("id-771", "2008-10-01", "10", "d023.0"))) patient_a.add_event(new_event(("id-771", "2001-05-16", "9", "b104.0"))) return patient_a
def test_success_patient(caplog): caplog.set_level(logging.DEBUG) row = ("id-771", "1981-12-20", "M") patient = new_patient(row) assert patient != None assert patient.gender == "M" assert patient.birth_date.strftime('%Y-%m-%d') == "1981-12-20" patient_lkp = json.loads(patient.to_json()) assert patient_lkp["birth_date"] == "1981-12-20" assert patient_lkp["gender"] == "M"
def patient_a(): return new_patient(("id-771", "1981-12-20", "F"))
def test_invalid_birth_date(): assert new_patient(("id-771", "1981-12-32", "M")) == None
def test_invalid_birth_date_format(): assert new_patient(("id-771", "1981/12,20", "M")) == None
def test_invalid_gender(): assert new_patient(("id-771", "1981-12-20", "T")) == None
def test_empty_fields(): assert new_patient(("id-771", "", "M")) == None assert new_patient(("id-771", "1981-12-20", "")) == None
def test_missing_values(): assert new_patient(("id-771", "1981-12-20")) == None
def test_none(): assert new_patient(None) == None