def create_hospitalisations(patient, facility, n): for _ in range(n): hospitalisation = Hospitalisation() hospitalisation.patient = patient hospitalisation.facility = facility hospitalisation.date_of_admission = random_date(date(2000, 1, 1), date.today()) hospitalisation.date_of_discharge = random_date(hospitalisation.date_of_admission, date.today()) hospitalisation.reason_for_admission = 'Test' db.session.add(hospitalisation)
def f(patient, facility, n): for _ in range(n): dialysis = Dialysis() dialysis.patient = patient dialysis.facility = facility dialysis.from_date = random_date(date(2000, 1, 1), date.today()) if random.random() > 0.5: dialysis.to_date = random_date(dialysis.from_date, date.today()) dialysis.dialysis_type = random.choice(dialysis_types) db.session.add(dialysis)
def f(patient, facility, n): for _ in range(n): plasmapheresis = Plasmapheresis() plasmapheresis.patient = patient plasmapheresis.facility = facility plasmapheresis.from_date = random_date(date(2000, 1, 1), date.today()) if random.random() > 0.5: plasmapheresis.to_date = random_date(plasmapheresis.from_date, date.today()) plasmapheresis.no_of_exchanges = random.randint(1, 10) plasmapheresis.response = random.choice(plasmapheresis_responses) db.session.add(plasmapheresis)
def create_renal_imaging(patient, facility, n): for _ in range(n): renal_imaging = RenalImaging() renal_imaging.patient = patient renal_imaging.facility = facility renal_imaging.date = random_date(date(2000, 1, 1), date.today()) renal_imaging.imaging_type = random.choice(['USS', 'CT', 'MRI']) renal_imaging.right_present = random_bool() renal_imaging.left_present = random_bool() if renal_imaging.right_present: renal_imaging.right_type = random.choice(['transplant', 'natural']) renal_imaging.right_length = random.randint(11, 14) renal_imaging.right_cysts = random_bool() renal_imaging.right_calcification = random_bool() if renal_imaging.right_calcification: renal_imaging.right_nephrocalcinosis = random_bool() renal_imaging.right_nephrolithiasis = random_bool() if renal_imaging.left_present: renal_imaging.left_type = random.choice(['transplant', 'natural']) renal_imaging.left_length = random.randint(11, 14) renal_imaging.left_cysts = random_bool() renal_imaging.left_calcification = random_bool() if renal_imaging.left_calcification: renal_imaging.left_nephrocalcinosis = random_bool() renal_imaging.left_nephrolithiasis = random_bool() db.session.add(renal_imaging)
def f(patient, facility, n): for _ in range(n): transplant = Transplant() transplant.patient = patient transplant.facility = facility transplant.transplant_date = random_date(date(2000, 1, 1), date.today()) transplant.transplant_type = random.choice(transplant_types) transplant.recurred = random_bool() if transplant.recurred: transplant.date_recurred = random_date(transplant.transplant_date, date.today()) if random.random() > 0.75: transplant.date_failed = random_date(transplant.transplant_date, date.today()) db.session.add(transplant)
def f(patient, facility, n): for _ in range(n): medication = Medication() medication.patient = patient medication.facility = facility medication.from_date = random_date(date(2000, 1, 1), date.today()) if random.random() > 0.5: medication.to_date = random_date(medication.from_date, date.today()) medication.name = random.choice(MEDICATION_NAMES) medication.dose_quantity = random.randint(1, 10) medication.dose_unit = random.choice(medication_dose_units) medication.frequency = random.choice(medication_frequencies) medication.route = random.choice(medication_routes) db.session.add(medication)
def create_posts(n): for x in range(n): d = random_date(date(2008, 1, 1), date.today()) post = Post() post.title = '%s Newsletter' % d.strftime('%b %Y') post.body = generate_lorem_ipsum(n=3, html=False) post.published = d db.session.add(post)
def create_patients(n): # TODO create data for remote facilities radar_facility = get_radar_facility() unit_facilities = Facility.query\ .join(Facility.unit)\ .filter(Facility.is_internal)\ .all() disease_groups = DiseaseGroup.query.all() result_group_definitions = ResultGroupDefinition.query.all() create_dialysis = create_dialysis_f() create_medications = create_medications_f() create_transplants = create_transplants_f() create_plasmapheresis = create_plasmapheresis_f() for _ in range(n): patient = Patient() patient.recruited_date = random_date(date(2008, 1, 1), date.today()) db.session.add(patient) gender = generate_gender() create_demographics(patient, radar_facility, gender) for facility in random.sample(unit_facilities, random.randint(1, 3)): unit_patient = UnitPatient(unit=facility.unit, patient=patient) unit_patient.created_date = random_date(patient.recruited_date, date.today()) db.session.add(unit_patient) create_demographics(patient, facility, gender) create_result_groups(patient, facility, result_group_definitions, 10) create_dialysis(patient, facility, 5) create_medications(patient, facility, 5) create_transplants(patient, facility, 3) create_hospitalisations(patient, facility, 3) create_plasmapheresis(patient, facility, 3) create_renal_imaging(patient, facility, 3) disease_group = random.choice(disease_groups) disease_group_patient = DiseaseGroupPatient(disease_group=disease_group, patient=patient) disease_group_patient.created_date = random_date(patient.recruited_date, date.today()) db.session.add(disease_group_patient)