async def register_investigator(request): """Updates auth information for the authorized account""" required_fields = ['name'] general.validate_fields(required_fields, request.json) name = request.json.get('name') clinic_signer = request.app.config.SIGNER_INVESTIGATOR # .get_public_key().as_hex() client_txn = consent_transaction.create_investigator_client( txn_signer=clinic_signer, batch_signer=clinic_signer) clinic_txn = ehr_transaction.create_investigator( txn_signer=clinic_signer, batch_signer=clinic_signer, name=name) batch, batch_id = ehr_transaction.make_batch_and_id( [client_txn, clinic_txn], clinic_signer) await security_messaging.add_investigator(request.app.config.VAL_CONN, request.app.config.TIMEOUT, [batch]) try: await security_messaging.check_batch_status( request.app.config.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 = ehr_transaction.make_batch_and_id( [grant_read_ehr_permission_txn], client_signer) await security_messaging.request_inform_document_consent( request.app.config.VAL_CONN, request.app.config.TIMEOUT, [batch], client_key) try: await security_messaging.check_batch_status( request.app.config.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 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 = ehr_transaction.set_eligible(txn_signer=client_signer, batch_signer=client_signer, uid=uid, eligible=eligible) batch, batch_id = ehr_transaction.make_batch_and_id([client_txn], client_signer) await security_messaging.set_eligible(request.app.config.VAL_CONN, request.app.config.TIMEOUT, [batch], client_key) try: await security_messaging.check_batch_status( request.app.config.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 revoke_investigator_access(request, investigator_pkey): """Updates auth information for the authorized account""" hospital_key = general.get_request_key_header(request) client_signer = general.get_signer(request, hospital_key) revoke_access_to_share_data_txn = consent_transaction.revoke_investigator_access( txn_signer=client_signer, batch_signer=client_signer, dest_pkey=investigator_pkey) batch, batch_id = ehr_transaction.make_batch_and_id( [revoke_access_to_share_data_txn], client_signer) await security_messaging.revoke_investigator_access( request.app.config.VAL_CONN, request.app.config.TIMEOUT, [batch], hospital_key) try: await security_messaging.check_batch_status( request.app.config.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 register_new_patient(request): """Updates auth information for the authorized account""" # keyfile = common.get_keyfile(request.json.get['signer']) required_fields = ['name', 'surname'] general.validate_fields(required_fields, request.json) name = request.json.get('name') surname = request.json.get('surname') # private_key = common.get_signer_from_file(keyfile) # signer = CryptoFactory(request.app.config.CONTEXT).new_signer(private_key) patient_signer = request.app.config.SIGNER_PATIENT # .get_public_key().as_hex() client_txn = consent_transaction.create_patient_client( txn_signer=patient_signer, batch_signer=patient_signer) # Consent network batch, batch_id = consent_transaction.make_batch_and_id([client_txn], patient_signer) await security_messaging.add_patient(request.app.config.CONSENT_VAL_CONN, request.app.config.TIMEOUT, [batch]) 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 # EHR network patient_txn = ehr_transaction.create_patient(txn_signer=patient_signer, batch_signer=patient_signer, name=name, surname=surname) batch, batch_id = ehr_transaction.make_batch_and_id([patient_txn], patient_signer) await security_messaging.add_patient(request.app.config.EHR_VAL_CONN, request.app.config.TIMEOUT, [batch]) try: await security_messaging.check_batch_status( request.app.config.EHR_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""" investigator_pkey = general.get_request_key_header(request) client_signer = general.get_signer(request, investigator_pkey) # LOGGER.debug('request.json: ' + str(request.json)) # data_list = request.json # data_txns = [] # for data in data_list: has_signed_inform_consent = \ await security_messaging.has_signed_inform_consent( request.app.config.VAL_CONN, patient_pkey, investigator_pkey) if not has_signed_inform_consent: raise ApiBadRequest("No signed inform consent between patient '" + patient_pkey + "' and investigator '" + investigator_pkey + "'") ehr = await security_messaging.get_ehr_by_id(request.app.config.VAL_CONN, patient_pkey, ehr_id) data_txn = ehr_transaction.add_data(txn_signer=client_signer, batch_signer=client_signer, uid=ehr.id, height=ehr.height, weight=ehr.weight, a1c=ehr.A1C, fpg=ehr.FPG, ogtt=ehr.OGTT, rpgt=ehr.RPGT, event_time=ehr.event_time) batch, batch_id = ehr_transaction.make_batch_and_id([data_txn], client_signer) await security_messaging.import_screening_data(request.app.config.VAL_CONN, request.app.config.TIMEOUT, [batch], investigator_pkey) try: await security_messaging.check_batch_status( request.app.config.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 add_ehr(request): """Updates auth information for the authorized account""" hospital_pkey = general.get_request_key_header(request) required_fields = [ 'patient_pkey', 'id', 'height', 'weight', 'A1C', 'FPG', 'OGTT', 'RPGT' ] general.validate_fields(required_fields, request.json) patient_pkey = request.json.get('patient_pkey') ehr_id = 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 = general.get_signer(request, hospital_pkey) ehr_txn = ehr_transaction.add_ehr(txn_signer=client_signer, batch_signer=client_signer, uid=ehr_id, client_pkey=patient_pkey, height=height, weight=weight, a1c=a1c, fpg=fpg, ogtt=ogtt, rpgt=rpgt) batch, batch_id = ehr_transaction.make_batch_and_id([ehr_txn], client_signer) await security_messaging.add_ehr(request.app.config.EHR_VAL_CONN, request.app.config.CONSENT_VAL_CONN, request.app.config.TIMEOUT, [batch], hospital_pkey, patient_pkey) try: await security_messaging.check_batch_status( request.app.config.EHR_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 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 = ehr_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 = ehr_transaction.make_batch_and_id([client_txn], client_signer) await security_messaging.update_investigator(request.app.config.VAL_CONN, request.app.config.TIMEOUT, [batch], client_key) try: await security_messaging.check_batch_status( request.app.config.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())