示例#1
0
文件: app.py 项目: tadinve/diags
def add_patient(patient_id):
    from forms import PatientForm
    if patient_id:
        id = int(patient_id.replace('P00', '').replace(
            'P0', '').replace('P', ''))
        patient = Patient.query.get(id)
    else:
        patient = Patient()
    form = PatientForm(obj=patient)
    if form.validate_on_submit():
        if 'photo' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['photo']
        # if user does not select file, browser also
        # submit an empty part without filename
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = uuid.uuid4().hex+'.' + \
                secure_filename(file.filename).split('.')[-1].lower()
            form.photo.data.save(os.path.join(
                app.config['UPLOAD_FOLDER'], 'patients', filename))
            form.populate_obj(patient)
            patient.photo = filename
            patient.gender = Gender(form.gender.data)
            db.session.add(patient)
            db.session.commit()
            url = url_for('patient_profile', patient_id=repr(patient))
            flash(
                'Patient saved with ID: {}, <a href="{}">view patient profile</a>'.format(repr(patient), url))
        return redirect(url_for('add_patient'))
    return render_template('add-patient.html', form=form)
示例#2
0
def get_patient_for_user(appt, user, access_token):
    patient = appt['patient']
    p = None
    try:
        p = Patient.objects.get(drchrono_id=patient)
    except Patient.DoesNotExist:
        patient_uri = drchrono_base_url + patients_url + '/' + str(patient)
        patient_data = requests.get(
            patient_uri,
            headers={'Authorization': 'Bearer %s' % access_token}
        ).json()
        p = Patient()
        p.drchrono_id = patient
        p.first_name = patient_data.get('first_name')
        p.last_name = patient_data.get('last_name')
        p.email = patient_data.get('email')
        p.gender = patient_data.get('gender')
        p.race = patient_data.get('race')
        p.photo = patient_data.get('photo')
        p.drchrono_doctor_id = patient_data.get('doctor')
        p.user_id = user.id
        p.save()
    return p
示例#3
0
def patientAdd(request):
    otherVars = {'pageType': 'logon', 'UserInfo': request.user.first_name}

    # if request method is post
    if request.method == 'POST':
        addPatientForm = AddPatientForm(request.POST)

        # input validation for add user and user profile form
        if addPatientForm.is_valid():
            # save the user and user profile object into database
            patientIns = Patient()
            patientIns.nric = request.POST['nric']
            patientIns.full_name = request.POST['full_name']
            patientIns.contact_num = request.POST['contact_num']
            patientIns.gender = request.POST['gender']
            patientIns.dob = request.POST['dob']
            patientIns.address = request.POST['address']
            patientIns.postalcode = request.POST['postalcode']
            patientIns.nok = request.POST['nok']
            patientIns.age = date.today().year - int(
                str(patientIns.dob).split('-')[0])
            patientIns.email = request.POST['email']
            patientIns.allergy = request.POST['allergy']
            patientIns.visit_time = time()
            patientIns.save()
            return HttpResponseRedirect(reverse('patientView'))
    else:
        addPatientForm = AddPatientForm()

    # Define header groups
    hgrps = (
        {
            'name': 'Patient Information',
            'lblwidth': '160'
        },
        {
            'name': 'Next-of-Kin Information',
            'lblwidth': '160'
        },
    )
    # For first header group
    addPatientForm.fields["nric"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["nric"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["full_name"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["full_name"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["contact_num"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["contact_num"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["gender"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["gender"].widget.attrs['wsize'] = '120'

    # # For first header group
    addPatientForm.fields["dob"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["dob"].widget.attrs['wsize'] = '150'

    addPatientForm.fields["address"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["address"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["postalcode"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["postalcode"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["email"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["email"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["allergy"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["allergy"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["nok"].widget.attrs['hgrp'] = '1'
    addPatientForm.fields["nok"].widget.attrs['wsize'] = '300'

    return render(request, 'main/patientchng.html', {
        'otherVars': otherVars,
        'addPatientForm': addPatientForm,
        'hgrps': hgrps
    })