'Update missing status for person'

@staticmethod
def note_onaccept(form):

    db = current.db
    s3db = current.s3db
    pe_table = s3db.pr_pentity
    ntable = db.pr_note
    ptable = s3db.pr_person
    if isinstance(form, (int, long, str)):
        _id = form
    elif hasattr(form, 'vars'):
        _id = form.vars.id
    else:
        _id = form.id
    note = ntable[_id]
    if (not note):
        return
    query = ((ntable.pe_id == note.pe_id) & (ntable.deleted != True))
    mq = ((query & ntable.status) == 1)
    fq = (query & ntable.status.belongs((2, 3)))
    mr = db(mq).select(ntable.id, ntable.timestmp, orderby=(~ ntable.timestmp), limitby=(0, 1)).first()
    fr = db(fq).select(ntable.id, ntable.timestmp, orderby=(~ ntable.timestmp), limitby=(0, 1)).first()
    missing = False
    if ((mr and (not fr)) or (fr.timestmp < mr.timestmp)):
        missing = True
    query = (ptable.pe_id == note.pe_id)
    db(query).update(missing=missing)
    if note.deleted:
        try:
            location_id = form.location_id
        except:
            pass
        else:
            ttable = s3db.sit_presence
            query = ((((ptable.pe_id == note.pe_id) & (ttable.uuid == ptable.uuid)) & (ttable.location_id == location_id)) & (ttable.timestmp == note.timestmp))
    if note.location_id:
        tracker = S3Tracker()
        tracker(query=query).set_location(note.location_id, timestmp=note.timestmp)
    return
