예제 #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_xrayOutcome_normal(self):
     self.assertEqual('Normal', getXrayOutcome('female', 0, 5.5, 0))
     self.assertEqual('Normal', getXrayOutcome('male', 0, 9.5, 0))
     self.assertEqual('Normal', getXrayOutcome('female', 0, 5.5, 1))
     self.assertEqual('Normal', getXrayOutcome('male', 0, 5.5, 2))
예제 #3
0
 def test_xrayOutcome_severe(self):
     self.assertEqual('Severe', getXrayOutcome('female', 2, 5.5, 1))
     self.assertEqual('Severe', getXrayOutcome('female', 2, 7.1, 0))
     self.assertEqual('Severe', getXrayOutcome('male', 2, 8.1, 1))
     self.assertEqual('Severe', getXrayOutcome('male', 2, 8.1, 2))
     self.assertEqual('Severe', getXrayOutcome('female', 2, 5.5, 2))
예제 #4
0
 def test_xrayOutcome_moderate(self):
     self.assertEqual('Moderate', getXrayOutcome('female', 2, 5.5, 0))
     self.assertEqual('Moderate', getXrayOutcome('male', 2, 7.0, 0))
예제 #5
0
 def test_xrayOutcome_normal(self):
     self.assertEqual('Normal', getXrayOutcome('female', 0, 5.5, 0))
     self.assertEqual('Normal', getXrayOutcome('male',   0, 9.5, 0))
     self.assertEqual('Normal', getXrayOutcome('female', 0, 5.5, 1))
     self.assertEqual('Normal', getXrayOutcome('male',   0, 5.5, 2))
예제 #6
0
 def test_xrayOutcome_severe(self):
     self.assertEqual('Severe', getXrayOutcome('female', 2, 5.5, 1))
     self.assertEqual('Severe', getXrayOutcome('female', 2, 7.1, 0))
     self.assertEqual('Severe', getXrayOutcome('male',   2, 8.1, 1))
     self.assertEqual('Severe', getXrayOutcome('male',   2, 8.1, 2))
     self.assertEqual('Severe', getXrayOutcome('female', 2, 5.5, 2))
예제 #7
0
 def test_xrayOutcome_moderate(self):
     self.assertEqual('Moderate', getXrayOutcome('female', 2, 5.5, 0))
     self.assertEqual('Moderate', getXrayOutcome('male',   2, 7.0, 0))