def stl_case_activity_owner_group(table, row):
 db = current.db
 s3db = current.s3db
 stable = s3db.org_service
 rtable = stable.with_alias('root_service')
 left = [stable.on((stable.id == table.service_id)), rtable.on((rtable.id == stable.root_service))]
 query = (table.id == row[table._id])
 row = db(query).select(rtable.name, left=left, limitby=(0, 1)).first()
 if (not row):
  return None
 root_service_name = row.name
 if (not root_service_name):
  return None
 if (root_service_name == INDIVIDUAL_SUPPORT):
  owner_group_uuid = 'CASE_MANAGEMENT'
 elif (root_service_name == MENTAL_HEALTH):
  owner_group_uuid = 'MENTAL_HEALTH'
 else:
  owner_group_uuid = 'GROUP_ACTIVITIES'
 gtable = current.auth.settings.table_group
 query = ((gtable.uuid == owner_group_uuid) & (gtable.deleted != True))
 group = db(query).select(gtable.id, limitby=(0, 1)).first()
 return (group.id if group else None)

def stl_case_activity_owner_group ( table , row ) : db = current . db s3db = current . s3db stable = s3db . org_service rtable = stable . with_alias ( 'root_service' ) left = [ stable . on ( ( stable . id == table . service_id ) ) , rtable . on ( ( rtable . id == stable . root_service ) ) ] query = ( table . id == row [ table . _id ] ) row = db ( query ) . select ( rtable . name , left = left , limitby = ( 0 , 1 ) ) . first ( ) if ( not row ) : return None root_service_name = row . name if ( not root_service_name ) : return None if ( root_service_name == INDIVIDUAL_SUPPORT ) : owner_group_uuid = 'CASE_MANAGEMENT' elif ( root_service_name == MENTAL_HEALTH ) : owner_group_uuid = 'MENTAL_HEALTH' else : owner_group_uuid = 'GROUP_ACTIVITIES' gtable = current . auth . settings . table_group query = ( ( gtable . uuid == owner_group_uuid ) & ( gtable . deleted != True ) ) group = db ( query ) . select ( gtable . id , limitby = ( 0 , 1 ) ) . first ( ) return ( group . id if group else None )
determine the owner group for dvr_case_activity records from the service type .