Ejemplo n.º 1
0
def add_vital_info(nhi, data):
    v = VitalInfo(**data)
    v.patient_nhi = nhi

    db.add(v)
    db.commit()

    if v.patient.latest_check_in is None or v.check_in_time > v.patient.latest_check_in:
        v.patient.latest_check_in = v.check_in_time

    db.commit()
    return v
Ejemplo n.º 2
0
def populate_database(num_patients, min_vital_infos, max_vital_infos):
    """
    Generates a number of Patients and a number of VitalInfos per patient and
    stores them in the database.

    Arguments
    num_patients    -- the number of patients to generate
    min_vital_infos -- the minimum number of VitalInfos to generate per Patient
    max_vital_infos -- the maximum number of VitalInfos to generate per Patient

    """
    departments = [
        Department(department_name="Cardiology"),
        Department(department_name="Emergency"),
        Department(department_name="Gynecology"),
        Department(department_name="Pediatrics"),
        Department(department_name="Obstetrics"),
        Department(department_name="Oncology"),
        Department(department_name="Orthopedics"),
        Department(department_name="Neurology")
    ]

    for i in xrange(num_patients):
        patient = Patient(**generate_patient())
        patient.departments.append(choice(departments))
        db.add(patient)
        db.commit()

        for j in xrange(randrange(min_vital_infos, max_vital_infos)):
            vitalinfo = VitalInfo(**generate_vital_info())
            vitalinfo.patient_nhi = patient.nhi

            lci = patient.latest_check_in
            vid = vitalinfo.check_in_time

            lci = vid if lci is None or vid > lci else lci
            patient.latest_check_in = lci

            db.add(vitalinfo)
            db.commit()