async def get_consent_request_list(conn, client_key): client = await get_client(conn, client_key) if Permission(type=Permission.GET_REQUESTS_LIST) in client.permissions: LOGGER.debug('has GET_REQUESTS_LIST permission: ' + str(client_key)) consent_request_list = await get_consent_request(conn, client_key) return consent_request_list raise ApiForbidden("Insufficient permission")
async def decline_request(conn, timeout, batches, client_key): client = await get_client(conn, client_key) if Permission(type=Permission.DECLINE_CONSENT) in client.permissions: LOGGER.debug('has permission: True') await _send(conn, timeout, batches) return else: LOGGER.debug('has permission: False') raise ApiForbidden("Insufficient permission")
async def get_consumers(conn, client_key): client = await get_client(conn, client_key) consumers_list = {} if Permission(type=Permission.GET_CONSUMERS_LIST) in client.permissions: list_consumer_address = data_helper.make_consumer_list_address() list_consumer_resources = await messaging.get_state_by_address( conn, list_consumer_address) for entity in list_consumer_resources.entries: cn = Consumer() cn.ParseFromString(entity.data) LOGGER.debug('consumer: ' + str(cn)) consumers_list[entity.address] = cn return consumers_list raise ApiForbidden("Insufficient permission")
async def add_data(conn, timeout, batches, client_key): client = await get_client(conn, client_key) if Permission(type=Permission.ADD_DATA) in client.permissions: LOGGER.debug('has ADD_DATA permission: True') # Has consent from patient # access = await has_data_processing_access(ehr_conn, dest_pkey, src_pkey) # if not access: # LOGGER.debug('no data processing access') # raise ApiForbidden("Insufficient permission") # await _send(conn, timeout, batches) return else: LOGGER.debug('has permission: False') raise ApiForbidden("Insufficient permission")
async def get_academics(conn, client_key): client = await get_client(conn, client_key) academic_list = {} if Permission(type=Permission.GET_ACADEMICS_LIST) in client.permissions: LOGGER.debug('has GET_ACADEMICS_LIST permission: ' + str(client_key)) list_academic_address = data_helper.make_academic_list_address() # Get Data Processing Access # data_processing_access = await get_consent_by_consumer(consent_conn, client_key) # data_processing_access_list = {} # for address, pt in data_processing_access.items(): # LOGGER.debug('data_processing_access: ' + str(pt)) # patient = await get_patient(ehr_conn, pt.src_pkey) # data_processing_access_list[pt.src_pkey] = patient # consent = await get_read_ehr_consent(conn, client_key) # consent_list = {} # for address, pt in consent.items(): # LOGGER.debug('consent: ' + str(pt)) # patient = await get_patient(conn, pt.src_pkey) # consent_list[pt.src_pkey] = patient # academic_list_resources = await messaging.get_state_by_address( conn, list_academic_address) for entity in academic_list_resources.entries: ac = Academic() ac.ParseFromString(entity.data) academic_list[entity.address] = ac LOGGER.debug('academic: ' + str(ac)) # Apply Access # for patient_address, pt in academic_list.items(): # LOGGER.debug('patient: ' + str(pt)) # if Permission(type=Permission.READ_OWN_PATIENT) in client.permissions and pt.public_key == client_key: # pass # elif pt.public_key not in data_processing_access_list: # pat2 = Patient() # patient_list[patient_address] = pat2 return academic_list # elif Permission(type=Permission.READ_OWN_PATIENT) in client.permissions: # LOGGER.debug('has READ_OWN_PATIENT: ' + str(client_key)) # # Get Data Processing Access # data_processing_access = await get_consent_by_consumer(consent_conn, client_key) # data_processing_access_list = {} # for address, pt in data_processing_access.items(): # LOGGER.debug('data_processing_access: ' + str(pt)) # patient = await get_patient(ehr_conn, pt.src_pkey) # data_processing_access_list[pt.src_pkey] = patient # return data_processing_access_list raise ApiForbidden("Insufficient permission")
async def get_data(conn, client_key): client = await get_client(conn, client_key) data_list = {} if Permission(type=Permission.READ_DATA) in client.permissions: LOGGER.debug('has READ_DATA permission: ' + str(client_key)) # Get Consumers with Consent consumers_with_consent = await get_consent_by_consumer( conn, client_key) for address, cn in consumers_with_consent.items(): LOGGER.debug('consumer with consent: ' + str(cn)) data_id_list_address = data_helper.make_data_list_by_consumer_address( cn.src_pkey) data_id_list_resources = await messaging.get_state_by_address( conn, data_id_list_address) for entity in data_id_list_resources.entries: data_id = entity.data.decode() data_address = data_helper.make_data_address(data_id) LOGGER.debug('get data: ' + str(data_address)) data_resources = await messaging.get_state_by_address( conn, data_address) for entity2 in data_resources.entries: entity_data_decode = entity2.data.decode() LOGGER.debug('entity_data_decode: ' + str(entity_data_decode)) cde = ConsumerDataExt() cde.ParseFromString(entity2.data) LOGGER.debug('data: ' + str(cde)) data_list[entity2.address] = cde # data_list_resources = await messaging.get_state_by_address(conn, data_list_address) # for entity in data_list_resources.entries: # cde = ConsumerDataExt() # cde.ParseFromString(entity.data) # # data_list[entity.address] = cde # LOGGER.debug('data: ' + str(cde)) # # Apply Consent # for patient_address, pt in patient_list.items(): # LOGGER.debug('patient: ' + str(pt)) # for claim_address, e in ehr_list.items(): # LOGGER.debug('ehr: ' + str(e)) # if patient_address == e.client_pkey: # LOGGER.debug('match!') # pt_local = patient_list[patient_address] # e.name = pt_local.name # e.surname = pt_local.surname # ehr_list[claim_address] = e return data_list elif Permission(type=Permission.READ_OWN_DATA) in client.permissions: data_id_list_address = data_helper.make_data_list_by_consumer_address( client_key) LOGGER.debug('has READ_OWN_DATA permission: ' + str(client_key)) data_id_list_resources = await messaging.get_state_by_address( conn, data_id_list_address) for entity in data_id_list_resources.entries: data_id = entity.data.decode() data_address = data_helper.make_data_address(data_id) LOGGER.debug('get data: ' + str(data_address)) data_resources = await messaging.get_state_by_address( conn, data_address) for entity2 in data_resources.entries: entity_data_decode = entity2.data.decode() LOGGER.debug('entity_data_decode: ' + str(entity_data_decode)) cde = ConsumerDataExt() cde.ParseFromString(entity2.data) LOGGER.debug('data: ' + str(cde)) data_list[entity2.address] = cde return data_list # elif Permission(type=Permission.READ_OWN_PATIENT_DATA) in client.permissions: # ehr_list_ids_address = ehr_helper.make_ehr_list_by_patient_address(client_key) # LOGGER.debug('has READ_OWN_PATIENT_DATA permission: ' + str(ehr_list_ids_address)) # ehr_list_ids = await messaging.get_state_by_address(ehr_conn, ehr_list_ids_address) # for entity in ehr_list_ids.entries: # ehr_id = entity.data.decode() # ehr_address = ehr_helper.make_ehr_address(ehr_id) # LOGGER.debug('get ehr: ' + str(ehr_address)) # ehr_resources = await messaging.get_state_by_address(ehr_conn, ehr_address) # for entity2 in ehr_resources.entries: # LOGGER.debug('get ehr entity2: ' + str(entity2.address)) # e = EHRWithUser() # e.ParseFromString(entity2.data) # ehr_list[entity2.address] = e # return ehr_list else: LOGGER.debug('neither READ_DATA permissions') raise ApiForbidden("Insufficient permission")