def get_report_programme(r): """ Identify the report programme @param r: the S3Request @returns: a tuple (programme_id, label) """ programme_id, label = None, None # Introspect the programme filter progfilter = r.get_vars.get("person_id$hours.programme_id__belongs") or \ r.get_vars.get("~.person_id$hours.programme_id__belongs") if progfilter: prog_ids = progfilter.split(",") if len(prog_ids) == 1: try: programme_id = long(prog_ids[0]) except (ValueError, TypeError): pass if programme_id: table = current.s3db.hrm_programme_hours field = table.programme_id label = current.T("Program: %(programme)s") % \ {"programme": field.represent(programme_id)} return programme_id, label
def get_report_organisation(r): """ Identify the report organisation @param r: the S3Request @returns: a tuple (organisation_id, label) """ db = current.db s3db = current.s3db organisation_id, label = None, None # Introspect the organisation filter first orgfilter = r.get_vars.get("~.organisation_id__belongs") if orgfilter: org_ids = orgfilter.split(",") if not org_ids: organisation_id = None elif len(org_ids) == 1: # Filtered to a single organisation try: organisation_id = long(org_ids[0]) except (ValueError, TypeError): pass else: # Do all filter-orgs belong to the same NS? otable = s3db.org_organisation query = (otable.id.belongs(org_ids)) & \ (otable.deleted == False) try: rows = db(query).select(otable.root_organisation, groupby = otable.root_organisation, ) except (ValueError, TypeError): pass else: if len(rows) == 1: organisation_id = rows.first().root_organisation if organisation_id is None: # Can the user see records of only one NS anyway? realms = current.auth.permission.permitted_realms("hrm_human_resource", "read") if realms: otable = s3db.org_organisation query = (otable.pe_id.belongs(realms)) & \ (otable.deleted == False) rows = db(query).select(otable.root_organisation, groupby = otable.root_organisation, ) if len(rows) == 1: organisation_id = rows.first().root_organisation if organisation_id: # Represent the organisation_id field = r.table.organisation_id label = field.represent(organisation_id) return organisation_id, label
def drk_person_anonymize(): """ Rules to anonymize a case file """ ANONYMOUS = "-" # Helper to produce an anonymous ID (pe_label) anonymous_id = lambda record_id, f, v: "NN%06d" % long(record_id) # General rule for attachments documents = ("doc_document", { "key": "doc_id", "match": "doc_id", "fields": { "name": ("set", ANONYMOUS), "file": "remove", "comments": "remove", }, "delete": True, }) # Cascade rule for case activities activity_details = [ ("dvr_response_action", { "key": "case_activity_id", "match": "id", "fields": { "comments": "remove", }, }), ("dvr_case_activity_need", { "key": "case_activity_id", "match": "id", "fields": { "comments": "remove", }, }), ("dvr_case_activity_update", { "key": "case_activity_id", "match": "id", "fields": { "comments": ("set", ANONYMOUS), }, }), ] rules = [ # Remove identity of beneficiary { "name": "default", "title": "Names, IDs, Reference Numbers, Contact Information, Addresses", "fields": { "first_name": ("set", ANONYMOUS), "last_name": ("set", ANONYMOUS), "pe_label": anonymous_id, "date_of_birth": drk_obscure_dob, "comments": "remove", }, "cascade": [ ("dvr_case", { "key": "person_id", "match": "id", "fields": { "comments": "remove", }, }), ("dvr_case_details", { "key": "person_id", "match": "id", "fields": { "lodging": "remove", }, }), ("pr_contact", { "key": "pe_id", "match": "pe_id", "fields": { "contact_description": "remove", "value": ("set", ""), "comments": "remove", }, "delete": True, }), ("pr_contact_emergency", { "key": "pe_id", "match": "pe_id", "fields": { "name": ("set", ANONYMOUS), "relationship": "remove", "phone": "remove", "comments": "remove", }, "delete": True, }), ("pr_address", { "key": "pe_id", "match": "pe_id", "fields": { "location_id": current.s3db.pr_address_anonymise, "comments": "remove", }, }), ("pr_person_details", { "key": "person_id", "match": "id", "fields": { "education": "remove", "occupation": "remove", }, }), ("pr_person_tag", { "key": "person_id", "match": "id", "fields": { "value": ("set", ANONYMOUS), }, "delete": True, }), ("dvr_residence_status", { "key": "person_id", "match": "id", "fields": { "reference": ("set", ANONYMOUS), "comments": "remove", }, }), ("dvr_service_contact", { "key": "person_id", "match": "id", "fields": { "reference": "remove", "contact": "remove", "phone": "remove", "email": "remove", "comments": "remove", }, }), ], }, # Remove activity details, appointments and notes { "name": "activities", "title": "Activity Details, Appointments, Notes", "cascade": [ ("dvr_case_activity", { "key": "person_id", "match": "id", "fields": { "subject": ("set", ANONYMOUS), "need_details": "remove", "outcome": "remove", "comments": "remove", }, "cascade": activity_details, }), ("dvr_case_appointment", { "key": "person_id", "match": "id", "fields": { "comments": "remove", }, }), ("dvr_case_language", { "key": "person_id", "match": "id", "fields": { "comments": "remove", }, }), ("dvr_note", { "key": "person_id", "match": "id", "fields": { "note": "remove", }, "delete": True, }), ], }, # Remove photos and attachments { "name": "documents", "title": "Photos and Documents", "cascade": [ ("dvr_case", { "key": "person_id", "match": "id", "cascade": [ documents, ], }), ("dvr_case_activity", { "key": "person_id", "match": "id", "cascade": [ documents, ], }), ("pr_image", { "key": "pe_id", "match": "pe_id", "fields": { "image": "remove", "url": "remove", "description": "remove", }, "delete": True, }), ], }, # TODO family membership ] return rules