async def set_eligible(request): client_key = general.get_request_key_header(request) required_fields = ['id', 'eligible'] general.validate_fields(required_fields, request.json) uid = request.json.get('id') eligible = bool(request.json.get('eligible')) client_signer = request.app.config.SIGNER_INVESTIGATOR # .get_public_key().as_hex() client_txn = trial_transaction.set_eligible(txn_signer=client_signer, batch_signer=client_signer, uid=uid, eligible=eligible) batch, batch_id = trial_transaction.make_batch_and_id([client_txn], client_signer) await security_messaging.set_eligible( request.app.config.INVESTIGATOR_VAL_CONN, request.app.config.CONSENT_VAL_CONN, request.app.config.TIMEOUT, [batch], client_key) try: await security_messaging.check_batch_status( request.app.config.INVESTIGATOR_VAL_CONN, [batch_id]) except (ApiBadRequest, ApiInternalError) as err: # await auth_query.remove_auth_entry( # request.app.config.DB_CONN, request.json.get('email')) raise err return response.json(body={'status': general.DONE}, headers=general.get_response_headers())
async def request_inform_consent(request, patient_pkey): """Updates auth information for the authorized account""" client_key = general.get_request_key_header(request) client_signer = general.get_signer(request, client_key) grant_read_ehr_permission_txn = consent_transaction.request_inform_document_consent( txn_signer=client_signer, batch_signer=client_signer, patient_pkey=patient_pkey) batch, batch_id = trial_transaction.make_batch_and_id( [grant_read_ehr_permission_txn], client_signer) await security_messaging.request_inform_document_consent( request.app.config.CONSENT_VAL_CONN, request.app.config.TIMEOUT, [batch], client_key) try: await security_messaging.check_batch_status( request.app.config.CONSENT_VAL_CONN, [batch_id]) except (ApiBadRequest, ApiInternalError) as err: # await auth_query.remove_auth_entry( # request.app.config.DB_CONN, request.json.get('email')) raise err return response.json(body={'status': general.DONE}, headers=general.get_response_headers())
async def get_all_investigators(request): """Fetches complete details of all Accounts in state""" client_key = general.get_request_key_header(request) investigator_list = await security_messaging.get_investigators( request.app.config.INVESTIGATOR_VAL_CONN, request.app.config.CONSENT_VAL_CONN, client_key) investigator_list_json = [] for address, dp in investigator_list.items(): investigator_list_json.append({ 'public_key': dp.public_key, 'name': dp.name }) return response.json(body={'data': investigator_list_json}, headers=general.get_response_headers())
async def update_data(request): client_key = general.get_request_key_header(request) required_fields = ['id', 'height', 'weight', 'A1C', 'FPG', 'OGTT', 'RPGT'] general.validate_fields(required_fields, request.json) uid = request.json.get('id') height = request.json.get('height') weight = request.json.get('weight') A1C = request.json.get('A1C') FPG = request.json.get('FPG') OGTT = request.json.get('OGTT') RPGT = request.json.get('RPGT') client_signer = request.app.config.SIGNER_INVESTIGATOR # .get_public_key().as_hex() client_txn = trial_transaction.update_data(txn_signer=client_signer, batch_signer=client_signer, uid=uid, height=height, weight=weight, a1c=A1C, fpg=FPG, ogtt=OGTT, rpgt=RPGT) batch, batch_id = trial_transaction.make_batch_and_id([client_txn], client_signer) await security_messaging.update_investigator( request.app.config.INVESTIGATOR_VAL_CONN, request.app.config.CONSENT_VAL_CONN, request.app.config.TIMEOUT, [batch], client_key) try: await security_messaging.check_batch_status( request.app.config.INVESTIGATOR_VAL_CONN, [batch_id]) except (ApiBadRequest, ApiInternalError) as err: # await auth_query.remove_auth_entry( # request.app.config.DB_CONN, request.json.get('email')) raise err return response.json(body={'status': general.DONE}, headers=general.get_response_headers())
async def import_screening_data(request, patient_pkey, ehr_id): """Updates auth information for the authorized account""" res_json = general.get_response_from_ehr( request, "/ehrs/" + patient_pkey + "/" + ehr_id) investigator_pkey = general.get_request_key_header(request) client_signer = general.get_signer(request, investigator_pkey) data_json = res_json['data'] if not data_json: raise ApiBadRequest("Can not retrieve '" + ehr_id + "' EHR ' for '" + patient_pkey + "' patient") data_txn = trial_transaction.add_data(txn_signer=client_signer, batch_signer=client_signer, uid=data_json['id'], height=data_json['height'], weight=data_json['weight'], a1c=data_json['A1C'], fpg=data_json['FPG'], ogtt=data_json['OGTT'], rpgt=data_json['RPGT'], event_time=data_json['event_time']) batch, batch_id = trial_transaction.make_batch_and_id([data_txn], client_signer) await security_messaging.import_screening_data( request.app.config.INVESTIGATOR_VAL_CONN, request.app.config.CONSENT_VAL_CONN, request.app.config.TIMEOUT, [batch], investigator_pkey) try: await security_messaging.check_batch_status( request.app.config.INVESTIGATOR_VAL_CONN, [batch_id]) except (ApiBadRequest, ApiInternalError) as err: # await auth_query.remove_auth_entry( # request.app.config.DB_CONN, request.json.get('email')) raise err return response.json(body={'status': general.DONE}, headers=general.get_response_headers())
async def get_all_data_from_investigators(request): """Fetches complete details of all Accounts in state""" client_key = general.get_request_key_header(request) data_list = await security_messaging.get_data_from_investigators( request.app.config.INVESTIGATOR_VAL_CONN, request.app.config.CONSENT_VAL_CONN, client_key) data_list_json = [] for address, data in data_list.items(): data_list_json.append({ 'id': data.id, 'height': data.height, 'weight': data.weight, 'A1C': data.A1C, 'FPG': data.FPG, 'OGTT': data.OGTT, 'RPGT': data.RPGT, 'event_time': data.event_time, 'eligible': data.eligible }) return response.json(body={'data': data_list_json}, headers=general.get_response_headers())