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 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 test_success_new_event(): row = ("id-972", "2015-09-21", "9", "367.0") event = new_event(row) assert event != None assert event.system == e.SYSTEM_9 assert event.date.strftime('%Y-%m-%d') == "2015-09-21" event_lkp = json.loads(event.to_json()) assert event_lkp["date"] == "2015-09-21" assert event_lkp["system"] == e.SYSTEM_9 assert event_lkp["code"] == "367.0"
def test_another_new_event(): row = ("id-972", "2013-07-11", "10", "Z01.00") event = new_event(row) assert event != None assert event.system == e.SYSTEM_10 assert event.date.strftime('%Y-%m-%d') == "2013-07-11" event_lkp = json.loads(event.to_json()) assert event_lkp["date"] == "2013-07-11" assert event_lkp["system"] == e.SYSTEM_10 assert event_lkp["code"] == "Z01.00"
def event_a(): return new_event(("id-771","2015-09-21", "9", "367.0"))
def test_invalid_version(): row = ("id-972", "2015-09-12", "7", "367.0") assert new_event(row) == None
def test_invalid_date(): row = ("id-972", "2015-09-45", "9", "367.0") assert new_event(row) == None
def test_invalid_date_format(): row = ("id-972", "2015/09/21", "9", "367.0") assert new_event(row) == None
def test_missing_value(): row = ("2015-09-21", "9") assert new_event(row) == None