def add_patient_to_unit(patient, unit): unit_patient = UnitPatient() unit_patient.patient = patient unit_patient.unit = unit # TODO permissions db.session.add(unit_patient)
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)