'Updates the number of total/available beds of a hospital'

@staticmethod
def hms_bed_capacity_onaccept(form):

    if isinstance(form, Row):
        formvars = form
    else:
        formvars = form.vars
    db = current.db
    ctable = db.hms_bed_capacity
    htable = db.hms_hospital
    query = ((ctable.id == formvars.id) & (htable.id == ctable.hospital_id))
    hospital = db(query).select(htable.id, limitby=(0, 1))
    if hospital:
        hospital = hospital.first()
        a_beds = ctable.beds_available.sum()
        t_beds = ctable.beds_baseline.sum()
        query = ((ctable.hospital_id == hospital.id) & (ctable.deleted == False))
        count = db(query).select(a_beds, t_beds)
        if count:
            a_beds = count[0]._extra[a_beds]
            t_beds = count[0]._extra[t_beds]
        db((htable.id == hospital.id)).update(total_beds=t_beds, available_beds=a_beds)
