Exemplo n.º 1
0
 def validate_hkid(self, hkid):
     d = re.search("(^[a-zA-Z])(\d{7})", hkid.data)
     if d is None:
         raise ValidationError('Invalid Hong Kong ID')
     else:
         id = patients.find_one({'HKID': d.string})
         if id is not None:
             raise ValidationError('Patient registered already')
Exemplo n.º 2
0
 def delete_patient(delhkid):
     form = SearchPatients
     if current_user.is_authenticated:
         id = delhkid
         name = patients.find_one({'HKID': id})['name']
         confirmed = request.form.get('confirm')
         flash(f'Would you like to delete patient {name} ID {id}?',
               'del_confirm')
         if confirmed:
             patients.delete_one({'name': name, 'HKID': id})
             flash(f'Patient {name} deleted', 'info')
             return redirect(url_for('index'))
         return render_template('deletepatient.html', id=id, form=form)
Exemplo n.º 3
0
 def details(pid):
     form = SearchPatients
     id = pid
     result = patients.find_one({'HKID': id})
     dob = result['DOB']
     age = int((datetime.today() - dob).days / 365.2425)
     furesults = followups.find({'HKID': id}).sort('dtof', 1)
     return render_template('details.html',
                            form=form,
                            id=id,
                            result=result,
                            age=age,
                            furesults=furesults,
                            datetime=datetime)
Exemplo n.º 4
0
def delete_notice(id, date):
    name = patients.find_one({'HKID': id})['name']
    apdate = date.astimezone(timezone('Asia/Hong_Kong'))
    subj = f'Appointment Cancellation of patient {name}'
    recip = ['*****@*****.**', '*****@*****.**']
    text = f"""
            System generated notification.
            Patient: {name}
            ID: {id} 
            cancelled the appointment of the following date and time:
            Date: {apdate: %d-%m-%Y}({apdate: %A})
            Time: {apdate: %H:%M}
            Please delete the appointment from calendar.
            """
    msg = Message(subj, recip, text)
    mail.send(msg)
    return redirect(url_for('index'))
Exemplo n.º 5
0
 def new_fus(id):
     name = patients.find_one({'HKID': id})['name']
     form = NewFolloups()
     if form.validate_on_submit():
         stage = form.stage.data
         eyes = form.eyes.data
         dtof = form.dtof.data
         exfu = followups.find_one({
             'HKID': id,
             'stage': stage,
             'eyes': eyes
         })
         if exfu is None:
             if dtof > datetime.today():
                 followups.insert({
                     'dtof': dtof,
                     'HKID': id,
                     'stage': stage,
                     'eyes': eyes
                 })
                 appointment_notice(name, id, dtof, stage)
             else:
                 followups.insert({
                     'dtof': dtof,
                     'HKID': id,
                     'stage': stage,
                     'eyes': eyes,
                     'md': form.md.data,
                     'psd': form.psd.data,
                     'iop1': form.iop1.data,
                     'iop2': form.iop2.data,
                     'vfi': form.vfi.data,
                     'cct': form.cct.data,
                     'rnfl': form.rnfl.data,
                     'rim': form.rim.data,
                     'disc': form.disc.data,
                     'vcd': form.vcd.data,
                     'cup': form.cup.data,
                     're': form.re.data
                 })
                 flash('New follow up recorded', 'info')
         else:
             flash('Duplicated record! Please check')
     return render_template('followups.html', form=form, id=id, name=name)
Exemplo n.º 6
0
 def updaterecord(uid, stage, eye):
     if current_user.is_authenticated:
         name = patients.find_one({'HKID': uid})['name']
         form = UpdateFollowup()
         id = uid
         record = followups.find_one({
             'HKID': id,
             'stage': stage,
             'eyes': eye
         })
         if form.validate_on_submit():
             followups.update_one(
                 record, {
                     '$set': {
                         'md': form.md.data,
                         'psd': form.psd.data,
                         'iop1': form.iop1.data,
                         'iop2': form.iop2.data,
                         'vfi': form.vfi.data,
                         'cct': form.cct.data,
                         'rnfl': form.rnfl.data,
                         'rim': form.rim.data,
                         'disc': form.disc.data,
                         'vcd': form.vcd.data,
                         'cup': form.cup.data,
                         're': form.re.data
                     }
                 })
             flash('Record updated', 'info')
             return redirect(url_for('index'))
         else:
             flash('Please update the record')
     return render_template('updaterecord.html',
                            name=name,
                            id=id,
                            form=form,
                            record=record)
Exemplo n.º 7
0
def appointment_notice(name, id, dtof, stage):
    c = Calendar()
    atte = (['*****@*****.**', '*****@*****.**'])
    esubj = f'Appointment of patient {name}'
    mobile = patients.find_one({'HKID': id})['mobile']
    progress = ['Baseline 1', 'Baseline 2', 'Month 4', 'Month 8',
                'Month 12'][stage]
    econt = f"""
            Name: {name}, ID: {id}, phone no.: {mobile}
            Progress: {progress}
            """
    e = Event(name=esubj, description=econt, attendees=atte)
    e.begin = dtof.astimezone(timezone('Asia/Hong_Kong'))
    e.duration = timedelta(hours=3)
    c.events.add(e)
    with open('appt.ics', 'w') as f:
        f.write(str(c))
    subj = f'New Appointment of patient {name}'
    recip = ['*****@*****.**', '*****@*****.**']
    text = f"""
            System generated notification.
            Patient: {name} 
            ID: {id}
            Phone: {mobile} 
            has a new appointment at:
            Date: {dtof: %d-%m-%Y}({dtof: %A}) 
            Time: {dtof:%H:%M}.
            Progress: {progress}
            Please add to calendar.
            """
    msg = Message(subj, recip, text)
    with open("appt.ics") as fp:
        msg.attach("appt.ics", "appt/ics", fp.read())
        mail.send(msg)
        flash('New appointment. Email notification sent', 'info')
        return redirect(url_for('index'))