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())
示例#2
0
async def decline_inform_consent(request, investigator_pkey):
    """Updates auth information for the authorized account"""
    client_key = general.get_request_key_header(request)
    client_signer = general.get_signer(request, client_key)
    revoke_data_processing_txn = consent_transaction.decline_inform_consent(
        txn_signer=client_signer,
        batch_signer=client_signer,
        investigator_pkey=investigator_pkey)

    batch, batch_id = consent_transaction.make_batch_and_id(
        [revoke_data_processing_txn], client_signer)

    await security_messaging.decline_inform_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 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())
示例#4
0
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())
示例#5
0
async def add_data(request):
    """Updates auth information for the authorized account"""
    consumer_pkey = general.get_request_key_header(request)
    required_fields = ['id', 'field1', 'field2', 'field3']
    general.validate_fields(required_fields, request.json)

    data_id = request.json.get('id')
    field1 = request.json.get('field1')
    field2 = request.json.get('field2')
    field3 = request.json.get('field3')

    client_signer = general.get_signer(request, consumer_pkey)

    data_txn = data_transaction.add_data(txn_signer=client_signer,
                                         batch_signer=client_signer,
                                         uid=data_id,
                                         field1=field1,
                                         field2=field2,
                                         field3=field3)

    batch, batch_id = data_transaction.make_batch_and_id([data_txn],
                                                         client_signer)

    await security_messaging.add_data(request.app.config.VAL_CONN,
                                      request.app.config.TIMEOUT, [batch],
                                      consumer_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())