Exemplo n.º 1
0
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())
Exemplo n.º 2
0
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())
Exemplo n.º 3
0
async def register_academic(request):
    """Updates auth information for the authorized account"""
    # keyfile = common.get_keyfile(request.json.get['signer'])
    required_fields = ['name']
    general.validate_fields(required_fields, request.json)

    name = request.json.get('name')

    # private_key = common.get_signer_from_file(keyfile)
    # signer = CryptoFactory(request.app.config.CONTEXT).new_signer(private_key)
    academic_signer = request.app.config.SIGNER_ACADEMIC  # .get_public_key().as_hex()

    client_txn = consent_transaction.create_academic_client(
        txn_signer=academic_signer, batch_signer=academic_signer)

    academic_txn = data_transaction.create_academic(
        txn_signer=academic_signer, batch_signer=academic_signer, name=name)

    batch, batch_id = consent_transaction.make_batch_and_id(
        [client_txn, academic_txn], academic_signer)

    await security_messaging.add_academic(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())
Exemplo n.º 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())
Exemplo n.º 5
0
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())
Exemplo n.º 6
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())