'Bed Capacity Validation'

@staticmethod
def hms_bed_capacity_onvalidation(form):

    db = current.db
    htable = db.hms_hospital
    ctable = db.hms_bed_capacity
    hospital_id = ctable.hospital_id.update
    bed_type = form.vars.bed_type
    query = ((ctable.hospital_id == hospital_id) & (ctable.bed_type == bed_type))
    row = db(query).select(ctable.id, limitby=(0, 1)).first()
    if (row and (str(row.id) != current.request.post_vars.id)):
        form.errors['bed_type'] = current.T('Bed    type    already    registered')
    elif ('unit_id' not in form.vars):
        query = (htable.id == hospital_id)
        hospital = db(query).select(htable.uuid, limitby=(0, 1)).first()
        if hospital:
            form.vars.unit_id = ('%s-%s' % (hospital.uuid, bed_type))
