Example #1
0
async def add_new_contract(request):
    """Updates auth information for the authorized account"""
    client_key = general.get_request_key_header(request)
    required_fields = ['id', 'client_pkey']
    general.validate_fields(required_fields, request.json)

    uid = request.json.get('id')
    contractor_pkey = request.json.get('client_pkey')

    client_signer = general.get_signer(request, client_key)

    contract_txn = transaction.add_contract(
        txn_signer=client_signer,
        batch_signer=client_signer,
        uid=uid,
        client_pkey=contractor_pkey
    )

    batch, batch_id = transaction.make_batch_and_id([contract_txn], client_signer)

    await security_messaging.add_contract(
        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())
Example #2
0
async def grant_access(request, doctor_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_access_txn = consent_transaction.grant_access(
        txn_signer=client_signer,
        batch_signer=client_signer,
        doctor_pkey=doctor_pkey)

    batch, batch_id = transaction.make_batch_and_id([grant_access_txn],
                                                    client_signer)

    await security_messaging.grant_access(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())
Example #3
0
async def update_claim(request):
    """Updates auth information for the authorized account"""
    # keyfile = common.get_keyfile(request.json.get['signer'])
    clinic_pkey = general.get_request_key_header(request)
    required_fields = [
        'claim_id', 'provided_service', 'client_pkey', 'provided_service'
    ]
    general.validate_fields(required_fields, request.json)

    claim_id = request.json.get('claim_id')
    provided_service = request.json.get('provided_service')
    patient_pkey = request.json.get('client_pkey')
    contract_id = request.json.get('contract_id')

    client_signer = general.get_signer(request, clinic_pkey)

    close_claim_txn = transaction.update_claim(
        txn_signer=client_signer,
        batch_signer=client_signer,
        uid=claim_id,
        patient_pkey=patient_pkey,
        provided_service=provided_service)

    # create_payment_txn = payment_transaction.create_payment(
    #     txn_signer=client_signer,
    #     batch_signer=client_signer,
    #     payment_id=str(helper.get_current_timestamp()),
    #     patient_pkey=patient_pkey,
    #     contract_id=contract_id,
    #     claim_id=claim_id
    # )

    batch, batch_id = transaction.make_batch_and_id([close_claim_txn],
                                                    client_signer)

    await security_messaging.update_claim(request.app.config.VAL_CONN,
                                          request.app.config.TIMEOUT, [batch],
                                          clinic_pkey, patient_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())
Example #4
0
async def register_new_claim(request):
    """Updates auth information for the authorized account"""
    # keyfile = common.get_keyfile(request.json.get['signer'])
    clinic_pkey = general.get_request_key_header(request)
    required_fields = ['patient_pkey', 'claim_id', 'description']
    general.validate_fields(required_fields, request.json)

    patient_pkey = request.json.get('patient_pkey')
    claim_id = request.json.get('claim_id')
    description = request.json.get('description')
    contract_id = request.json.get('contract_id')

    if contract_id is not None and contract_id != '':
        is_valid = await security_messaging.valid_contracts(
            request.app.config.VAL_CONN, patient_pkey, contract_id)
        if not is_valid:
            return response.text(body="Contract having '" + contract_id +
                                 "' id is not valid",
                                 status=ApiBadRequest.status_code,
                                 headers=general.get_response_headers())

    client_signer = general.get_signer(request, clinic_pkey)

    claim_txn = transaction.add_claim(txn_signer=client_signer,
                                      batch_signer=client_signer,
                                      uid=claim_id,
                                      description=description,
                                      client_pkey=patient_pkey,
                                      contract_id=contract_id)

    batch, batch_id = transaction.make_batch_and_id([claim_txn], client_signer)

    await security_messaging.add_claim(request.app.config.VAL_CONN,
                                       request.app.config.TIMEOUT, [batch],
                                       clinic_pkey, patient_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())
Example #5
0
async def add_new_pulse(request):
    """Updates auth information for the authorized account"""
    # keyfile = common.get_keyfile(request.json.get['signer'])
    client_key = general.get_request_key_header(request)
    required_fields = ['pulse', 'timestamp']
    general.validate_fields(required_fields, request.json)

    pulse = request.json.get('pulse')
    timestamp = request.json.get('timestamp')

    # private_key = common.get_signer_from_file(keyfile)
    # signer = CryptoFactory(request.app.config.CONTEXT).new_signer(private_key)
    # patient_signer = request.app.config.SIGNER  # .get_public_key().as_hex()
    client_signer = general.get_signer(request, client_key)
    current_times_str = str(helper.get_current_timestamp())

    pulse_txn = transaction.add_pulse(txn_signer=client_signer,
                                      batch_signer=client_signer,
                                      pulse=pulse,
                                      uid=current_times_str,
                                      timestamp=timestamp,
                                      client_pkey=client_key)

    batch, batch_id = transaction.make_batch_and_id([pulse_txn], client_signer)

    await security_messaging.add_pulse(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())
Example #6
0
async def add_new_payment(request):
    """Updates auth information for the authorized account"""
    # keyfile = common.get_keyfile(request.json.get['signer'])
    client_key = general.get_request_key_header(request)
    required_fields = ['patient_pkey', 'contract_id', 'claim_id']
    general.validate_fields(required_fields, request.json)

    # uid = request.json.get('id')
    patient_pkey = request.json.get('patient_pkey')
    contract_id = request.json.get('contract_id')
    claim_id = request.json.get('claim_id')

    client_signer = general.get_signer(request, client_key)
    payment_id = str(helper.get_current_timestamp())

    batch, batch_id = transaction.create_payment(txn_signer=client_signer,
                                                 batch_signer=client_signer,
                                                 payment_id=payment_id,
                                                 patient_pkey=patient_pkey,
                                                 contract_id=contract_id,
                                                 claim_id=claim_id)

    await security_messaging.create_payment(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 add_new_lab_test(request):
    """Updates auth information for the authorized account"""
    # keyfile = common.get_keyfile(request.json.get['signer'])
    client_key = general.get_request_key_header(request)
    required_fields = [
        'height', 'weight', 'gender', 'a_g_ratio', 'albumin',
        'alkaline_phosphatase', 'appearance', 'bilirubin', 'casts', 'color'
    ]
    general.validate_fields(required_fields, request.json)

    height = request.json.get('height')
    weight = request.json.get('weight')
    gender = request.json.get('gender')
    a_g_ratio = request.json.get('a_g_ratio')
    albumin = request.json.get('albumin')
    alkaline_phosphatase = request.json.get('alkaline_phosphatase')
    appearance = request.json.get('appearance')
    bilirubin = request.json.get('bilirubin')
    casts = request.json.get('casts')
    color = request.json.get('color')

    # private_key = common.get_signer_from_file(keyfile)
    # signer = CryptoFactory(request.app.config.CONTEXT).new_signer(private_key)
    # client_signer = request.app.config.SIGNER  # .get_public_key().as_hex()
    # if request.app.config.SIGNER_CLINIC.get_public_key().as_hex() == client_key:
    #     client_signer = request.app.config.SIGNER_CLINIC
    # elif request.app.config.SIGNER_PATIENT.get_public_key().as_hex() == client_key:
    #     client_signer = request.app.config.SIGNER_PATIENT
    # elif request.app.config.SIGNER_DOCTOR.get_public_key().as_hex() == client_key:
    #     client_signer = request.app.config.SIGNER_DOCTOR
    # elif request.app.config.SIGNER_LAB.get_public_key().as_hex() == client_key:
    #     client_signer = request.app.config.SIGNER_LAB
    # else:
    #     client_signer = request.app.config.SIGNER_PATIENT
    client_signer = general.get_signer(request, client_key)
    current_times_str = str(helper.get_current_timestamp())

    lab_test_txn = transaction.add_lab_test(
        txn_signer=client_signer,
        batch_signer=client_signer,
        height=height,
        weight=weight,
        gender=gender,
        a_g_ratio=a_g_ratio,
        albumin=albumin,
        alkaline_phosphatase=alkaline_phosphatase,
        appearance=appearance,
        bilirubin=bilirubin,
        casts=casts,
        color=color,
        uid=current_times_str,
        client_pkey=client_key)

    batch, batch_id = transaction.make_batch_and_id([lab_test_txn],
                                                    client_signer)

    await security_messaging.add_lab_test(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())