Пример #1
0
    def validate(qid, **kwargs):
        ccs_qids = {
            '51', '52', '53', '54', '61', '62', '63', '71', '73', '81', '83'
        }

        case_id = kwargs['row']['case_id']

        fail_validation_if_invalid_uuid(case_id)

        try:
            result = execute_in_connection_pool(
                "SELECT survey FROM casev2.cases WHERE case_id = %s LIMIT 1",
                (case_id, ),
                conn_pool=kwargs['db_connection_pool'])
            survey, = [row[0] for row in result]

        except Exception as e:
            print(f'Error looking up case {case_id}, Error: {e}')
            raise Invalid(f'Error looking up case ID: {case_id}')

        if not result:
            raise Invalid(f'Case does not exist in RM for Case ID "{case_id}"')

        if qid[:2] in ccs_qids and survey == "CENSUS":
            raise Invalid(
                f'CCS qid {qid} cannot be linked to CENSUS case_id {case_id}')

        if qid[:2] not in ccs_qids and survey == "CCS":
            raise Invalid(
                f'CENSUS qid {qid} cannot be linked to CCS case_id {case_id}')
Пример #2
0
 def validate(qid, **kwargs):
     try:
         qid_exists_in_db = execute_in_connection_pool("SELECT 1 FROM casev2.uac_qid_link WHERE qid = %s LIMIT 1",
                                                       (qid,), conn_pool=kwargs['db_connection_pool'])
     except Exception as e:
         print(f'Error looking up qid {qid}, Error: {e}')
         raise Invalid(f'Error looking up case ID: {qid}')
     if not qid_exists_in_db:
         raise Invalid(f'qid "{qid}" does not exist in RM')
Пример #3
0
 def validate(case_id, **kwargs):
     try:
         query = "SELECT 1 FROM casev2.cases WHERE case_id = %s AND case_type = 'HH'"
         case_id_exists = execute_in_connection_pool(query, (case_id,), conn_pool=kwargs['db_connection_pool'])
     except Exception as e:
         print(f'Error looking up case ID: {case_id}, Error: {e}')
         raise Invalid(f'Error looking up case ID: {case_id}')
     if not case_id_exists:
         raise Invalid(f'HH Case does not exist in RM for Case ID "{case_id}"')
Пример #4
0
    def validate(case_id, **kwargs):
        fail_validation_if_invalid_uuid(case_id)

        try:
            case_id_exists = execute_in_connection_pool(
                "SELECT 1 FROM casev2.cases WHERE case_id = %s", (case_id, ),
                conn_pool=kwargs['db_connection_pool'])
        except Exception as e:
            print(f'Error looking up case ID: {case_id}, Error: {e}')
            raise Invalid(f'Error looking up case ID: {case_id}')
        if not case_id_exists:
            raise Invalid(f'Case ID "{case_id}" does not exist in RM')
def get_case_id_from_uprn(uprn, line_number, conn_pool):
    result = db_helper.execute_in_connection_pool(
        'SELECT case_id FROM casev2.cases WHERE uprn = %s', (uprn, ),
        conn_pool=conn_pool)
    case_ids = [row[0] for row in result]
    if len(case_ids) < 1:
        raise ValueError(
            f'UPRN {uprn} does not match any cases, line {line_number}')
    if len(case_ids) > 1:
        raise ValueError(
            f'UPRN {uprn} matches multiple case IDs, line {line_number}')
    return case_ids[0]
Пример #6
0
    def validate(case_id, **kwargs):
        try:
            # If the case ID is not a valid UUID the database lookup will fail
            uuid.UUID(case_id, version=4)
        except Exception:
            raise Invalid(f'Cannot look up Case ID {case_id}, it is not a valid UUID')

        try:
            case_id_exists = execute_in_connection_pool("SELECT 1 FROM casev2.cases WHERE case_id = %s",
                                                        (case_id,), conn_pool=kwargs['db_connection_pool'])
        except Exception as e:
            print(f'Error looking up case ID: {case_id}, Error: {e}')
            raise Invalid(f'Error looking up case ID: {case_id}')
        if not case_id_exists:
            raise Invalid(f'Case ID "{case_id}" does not exist in RM')