def cover_protected_data(data_list, resource, patient_id, status='full'): ''' data_list : sometimes we don't wanna display all part of this resource, this list will tell us which to display,a list resource : json data that wanna to display, the format is dict patient_id : extract identifier of policy_list ''' privacy_policy = db.select_policy(patient_id) if (privacy_policy == -2): #No record in the database return resource policy_data = jd.json2list(privacy_policy,RESERVED_WORD) if type(data_list) is dict: jd.json_reduce_structure(data_list) data_list = jd.json2list(data_list, RESERVED_WORD) if isinstance(resource['resourceType'], unicode): s=resource['resourceType'] else: s=unicode(resource['resourceType'],"utf-8") jd.json_reduce_structure(resource) resource_data = jd.json2list(resource,RESERVED_WORD) for i in range(len(resource_data)): resource_data[i].insert(0,s) data = data_list for i in range(len(data)): data[i].insert(0,s) #If the query is only part of data,then do the intersection for i in range(len(data)): if data[i][1] == 'text' or data[i][1] == 'resourceType': continue tmp = retrieve(data[i],resource_data) if tmp[0] == 'Not_Found': data[i][-1] = 'Not in the online record' else: data[i][-1] = tmp[1] for i in range(len(data)): if data[i][1]=='text' or data[i][1]=='resourceType': continue tmp = retrieve(data[i],policy_data) # Not found or unmasked means we should not change the value if tmp[0] == 'Mask': # Here we need to filter the policy data[i][-1] = 'Protected data due to privacy policy' for i in range(len(data)): del data[i][0] result = jd.list2json(data,RESERVED_WORD) return result
example_policy = { "Patient": { "name": [{"text": "David Penrod"}], "resourceType": "Patient", "text": {"status": "generated", "div": "<div><p>David Penrod</p></div>"}, "meta": {"versionID": 1, "lastUpdated": "2016-01-13T15:31:33.555627"}, "gender": "male", "id": "a770136e-616f-45b0-8752-3be0ad9cab42", } } example_id = "a770136e-616f-45b0-8752-3be0ad9cab42" import database as db import json db.delete_record(example_id) db.insert_record(example_id, example_policy, None) if __name__ == "__main__": print json.dumps(db.select_policy("7ff9db40-783d-48c4-b564-fffa42d45e04"), indent=2)
example_policy = { "Patient": { "name": [{ "text": "David Penrod" }], "resourceType": "Patient", "text": { "status": "generated", "div": "<div><p>David Penrod</p></div>" }, "meta": { "versionID": 1, "lastUpdated": "2016-01-13T15:31:33.555627" }, "gender": "male", "id": "a770136e-616f-45b0-8752-3be0ad9cab42" } } example_id = "a770136e-616f-45b0-8752-3be0ad9cab42" import database as db import json db.delete_record(example_id) db.insert_record(example_id, example_policy, None) if __name__ == '__main__': print json.dumps(db.select_policy("7ff9db40-783d-48c4-b564-fffa42d45e04"), indent=2)