示例#1
0
def add_patient():
    "add new patient if logged in"
    if not session.get('logged_in'):  # logged_in key present and True
        abort(401)
    try:
        xray = bool2int(request.form['xray'])
        if not xray:
            flash('No Xray data, cannot make diagnosis')
            return redirect(url_for('new_patient'))

        patient_id = request.form['patient_id']   # should not be empty
        if len(patient_id) < 5:
# could flash(msg)
            raise BadRequestKeyError('patient id invalid, too short')
        ddensity = choice2int(request.form['double_density'])
        ob_diam = float(request.form['oblique_diameter'])
        app_shape = choice2appendage(request.form['appendage_shape'])
        gender = request.form['gender']
    except (BadRequestKeyError, Exception) as inst:
#       app.logger.warning('request.form %s', str(type(request.form)))
#       app.logger.warning("inst type %s args %s inst %s", str(type(inst)), inst.args, inst)
# we may: redirect if form incomplete (not store in db), re-raise exception, log messages
#       raise
#       raise BadRequestKeyError(*inst.args)
        flash('Patient info incomplete, please re-enter')
        return redirect(url_for('new_patient'))

    has_patient = get_params(patient_id)
    if has_patient:
        flash("patient id '%s' already exists, please re-enter" % patient_id)
        return redirect(url_for('new_patient'))

    x_outcome = ''
    if (xray > 0):
        x_outcome = getXrayOutcome(gender, ddensity, ob_diam, app_shape)
    dz = getNowTimeInt()
    ctmri = 0
    cur = g.db.cursor()
    cur.execute('insert into patients (patient_id, gender, date_created, \
                  xray, double_density, oblique_diameter, \
                  appendage_shape, xray_outcome, ctmri) values \
                  (%s, %s, %s, %s, %s, %s, %s, %s, %s);',
                 (patient_id, gender, dz, xray, ddensity, ob_diam,
                  app_shape, x_outcome, ctmri))
    g.db.commit()
    flash('New patient was successfully posted')
    return redirect(url_for('show_patient', patient_id=patient_id))
示例#2
0
 def test_choice2appendage(self):
     self.assertEqual(0, choice2appendage('Concave'))
     self.assertEqual(0, choice2appendage('Flat'))
     self.assertEqual(2, choice2appendage('Convex'))
     self.assertEqual(1, choice2appendage('Unsure'))
     self.assertEqual(1, choice2appendage(''))
示例#3
0
 def test_choice2appendage(self):
     self.assertEqual(0, choice2appendage('Concave'))
     self.assertEqual(0, choice2appendage('Flat'))
     self.assertEqual(2, choice2appendage('Convex'))
     self.assertEqual(1, choice2appendage('Unsure'))
     self.assertEqual(1, choice2appendage(''))