Пример #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
Пример #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()
Пример #3
0
def vital_info(nhi, vital_info_id):
    vitalinfo = VitalInfo.query.filter_by(
        patient_nhi=nhi, vital_info_id=vital_info_id).first()

    if not vitalinfo:
        return make_response("No vitalinfo for patient {} with id {}".format(nhi, vital_info_id))

    elif request.method == "GET":
        return jsonify(vitalinfo.serialize())

    elif request.method == "POST":
        vitalinfo_data = json.loads(request.data)
        vitalinfo = VitalInfo(**vitalinfo_data)
        vitalinfo.vital_info_id = vital_info_id
        vitalinfo = db.merge(vitalinfo)
        db.commit()

        return jsonify(vitalinfo.serialize())

    elif request.method == "DELETE":
        db.delete(vitalinfo)
        db.commit()

        return make_response("Deleted vitalinfo: {} from patient: {}".format(vital_info_id, nhi), 200)