Ejemplo n.º 1
0
def validate_fields(required_fields, request_json):
    try:
        for field in required_fields:
            if request_json.get(field) is None:
                raise ApiBadRequest("{} is required".format(field))
    except (ValueError, AttributeError):
        raise ApiBadRequest("Improper JSON format")
async def get_patient(conn, patient_key):
    list_patient_address = helper.make_patient_address(patient_key)
    patient_resources = await messaging.get_state_by_address(
        conn, list_patient_address)
    for entity in patient_resources.entries:
        lt = CreatePatient()
        lt.ParseFromString(entity.data)
        return lt
    raise ApiBadRequest("No such patient exist: " + str(patient_key))
Ejemplo n.º 3
0
async def get_evaluation(conn, record_id):
    list_patient_address = helper.make_evaluation_address(record_id)
    evaluation_resources = await messaging.get_state_by_address(
        conn, list_patient_address)
    for entity in evaluation_resources.entries:
        lt = Evaluation()
        lt.ParseFromString(entity.data)
        return lt
    raise ApiBadRequest("No such patient exist: " + str(record_id))
Ejemplo n.º 4
0
async def get_recordowner(conn, recordid):
    list_patient_address = helper.make_record_patient_address(recordid)
    recordowner = await messaging.get_state_by_address(conn,
                                                       list_patient_address)
    for entity in recordowner.entries:
        lt = RecordOwner()
        lt.ParseFromString(entity.data)
        return lt
    raise ApiBadRequest("No such entity exist: " + str(recordid))
Ejemplo n.º 5
0
async def get_consent_patient_doctor(conn, recordid):
    list_patient_address = helper.make_record_patient_doctor_conset_address(
        recordid)
    consent = await messaging.get_state_by_address(conn, list_patient_address)

    LOGGER.debug("CONSENT RECIEN SACADO " + str(consent))
    for entity in reversed(consent.entries):
        lt = ConsentDocPat()
        lt.ParseFromString(entity.data)
        return lt
    raise ApiBadRequest("No such entity exist: " + str(recordid))
Ejemplo n.º 6
0
async def check_batch_status(conn, batch_ids):
    status_request = client_batch_submit_pb2.ClientBatchStatusRequest(
        batch_ids=batch_ids, wait=True)
    validator_response = await conn.send(
        validator_pb2.Message.CLIENT_BATCH_STATUS_REQUEST,
        status_request.SerializeToString())

    status_response = client_batch_submit_pb2.ClientBatchStatusResponse()
    status_response.ParseFromString(validator_response.content)
    batch_status = status_response.batch_statuses[0].status
    if batch_status == client_batch_submit_pb2.ClientBatchStatus.INVALID:
        invalid = status_response.batch_statuses[0].invalid_transactions[0]
        raise ApiBadRequest(invalid.message)
    elif batch_status == client_batch_submit_pb2.ClientBatchStatus.PENDING:
        raise ApiInternalError("Transaction submitted but timed out")
    elif batch_status == client_batch_submit_pb2.ClientBatchStatus.UNKNOWN:
        raise ApiInternalError("Something went wrong. Try again later")