예제 #1
0
def get_capabilities_statement():

    request_id = log_utils.get_request_id(request)
    log_utils.log_handler_entry(request_id, request)

    format, error_description = handler_utils.determine_format(request,
                                                               is_fhir=True)
    if error_description:
        code = constants.INVALID_VALUE_ERROR
        return handler_utils.create_fhir_error_response(
            format, [code], request_id, [error_description], 406)

    valid, descriptions, codes = handler_utils.isValidFHIRCapabilitiesOrRolesRequest(
        request)
    if not valid:
        return handler_utils.create_fhir_error_response(
            format, codes, request_id, descriptions, 406)

    response = fhir_capabilities_service.get_fhir_capabilities(
        format, request.base_url, request_id)
    response = Response(response)

    handler_utils.add_content_type_header_to_response(format, response)
    log_utils.log_handler_exit(request_id, response.status, constants.SUCCESS)

    return response
def get_changed_organisations_list():
    request_id = log_utils.get_request_id(request)
    log_utils.log_handler_entry(request_id, request)
    route = request.url_root


    format, error_description = handler_utils.determine_format(request, is_fhir=False)
    if error_description:
        handler_utils.ord_error_log_and_abort(406, error_description, request_id)

    valid, description = handler_utils.isValidSyncAPIRequest(request)
    if not valid:
        handler_utils.ord_error_log_and_abort(406, description, request_id)


    try:
        resp_data, total_record_count = ord_sync_service.get_ord_organisations_changed_since(request.args, format, route,
                                                                                             request_id)
    except (exception.ServiceError, exception.InvalidDataError):
        handler_utils.ord_error_log_and_abort(500, "Service Unavailable", request_id)

    response = Response(resp_data)

    handler_utils.add_content_type_header_to_response(format, response)

    response.headers['X-Total-Count'] = total_record_count
    response.headers['Access-Control-Expose-Headers'] = 'X-Total-Count'

    log_utils.log_handler_exit(request_id, response.status, constants.SUCCESS)
    return response
def get_organisation(ods_code):
    """
    Endpoint returns a single ODS organisation
    ---
    parameters:
      - name: ods_code
        in: path
        type: string
        required: true
    responses:
      200:
        description: An ODS organisation record was returned in JSON by default or XML if parameter _format = xml
      404 NOT FOUND:
        description: No ODS organisation record was found
      406 NOT ACCEPTABLE:
        description: An invalid _format was supplied.  Valid options are json or xml
    """

    request_id = log_utils.get_request_id(request)
    log_utils.log_handler_entry(request_id, request)

    url_root = request.url_root

    format, error_description = handler_utils.determine_format(request,
                                                               is_fhir=False)
    if error_description:
        handler_utils.ord_error_log_and_abort(406, error_description,
                                              request_id)

    valid, description = handler_utils.isValidOdsCodeAPIRequest(request)
    if not valid:
        handler_utils.ord_error_log_and_abort(406, description, request_id)

    ods_code = str.upper(ods_code)

    try:
        response = ods_code_service.get_single_organisation(ods_code,
                                                            format,
                                                            url_root,
                                                            request_id,
                                                            is_fhir=False)

    except (exception.ServiceError, exception.InvalidDataError):
        handler_utils.ord_error_log_and_abort(500, "Service Unavailable",
                                              request_id)
    except:
        handler_utils.ord_error_log_and_abort(404, "Unknown Error", request_id)

    response = Response(response)

    handler_utils.add_content_type_header_to_response(format, response)
    log_utils.log_handler_exit(request_id, response.status, constants.SUCCESS)

    return response
def get_fhir_organisation(ods_code):
    """
    Endpoint returns a single ODS FHIR organization 
    ---
    parameters:
      - name: ods_code
        in: path
        type: string
        required: true
    responses:
      200:
        description: An ODS organisation record was returned in JSON by default or XML if parameter _format = xml
      404 NOT FOUND:
        description: No ODS organisation record was found
      406 NOT ACCEPTABLE:
        description: An invalid _format was supplied.  Valid options are json or xml
    """
    request_id = log_utils.get_request_id(request)
    log_utils.log_handler_entry(request_id, request)

    format, error_description = handler_utils.determine_format(request, is_fhir=True)
    if error_description:
        code = constants.INVALID_VALUE_ERROR
        return handler_utils.create_fhir_error_response(format, [code], request_id, [error_description], 406)

    valid, descriptions, codes = handler_utils.isValidFHIROdsCodeAPIRequest(request)
    if not valid:
        return handler_utils.create_fhir_error_response(format, codes, request_id, descriptions, 406)

    ods_code = str.upper(ods_code)
    url_root = request.url_root

    try:
        response = ods_code_service.get_single_organisation(ods_code, format, url_root, request_id, is_fhir=True)
    except (exception.ServiceError, exception.InvalidDataError):
        description = "Service Unavailable"
        code = constants.ACCESS_DENIED
        return handler_utils.create_fhir_error_response(format, [code], request_id, [description], 500)
    except exception.UnfoundOrgError:
        description = "No record found for supplied ODS code"
        code = constants.NO_RECORD_FOUND_ERROR
        return handler_utils.create_fhir_error_response(format, [code], request_id, [description], 404)
    except:
        code = constants.ACCESS_DENIED
        return handler_utils.create_fhir_error_response(format, [code], request_id, ["Unknown Error"], 404)

    response = Response(response)

    handler_utils.add_content_type_header_to_response(format, response)
    log_utils.log_handler_exit(request_id, response.status, constants.SUCCESS)

    return response
def get_fhir_organisations():
    """
    Endpoint returns a Bundle of ODS FHIR organizations
    ---
    parameters:
      - name: ods_code
        in: path
        type: string
        required: true
    responses:
      200:
        description: An ODS organisation record was returned in JSON by default or XML if parameter _format = xml
      404 NOT FOUND:
        description: No ODS organisation record was found
      406 NOT ACCEPTABLE:
        description: An invalid _format was supplied.  Valid options are json or xml
    """
    request_id = log_utils.get_request_id(request)
    log_utils.log_handler_entry(request_id, request)

    format, error_description = handler_utils.determine_format(request,
                                                               is_fhir=True)
    if error_description:
        code = constants.INVALID_VALUE_ERROR
        return handler_utils.create_fhir_error_response(
            format, [code], request_id, [error_description], 406)

    valid, descriptions, codes = handler_utils.isValidFHIROrganisationAPIRequest(
        request)
    if not valid:
        return handler_utils.create_fhir_error_response(
            format, codes, request_id, descriptions, 406)

    try:
        resp_data, returned_record_count, total_record_count = \
            fhir_organisations_service.get_fhir_organisations(request, format, request_id)
    except (exception.ServiceError, exception.InvalidDataError):
        description = "Service Unavailable"
        code = constants.ACCESS_DENIED
        return handler_utils.create_fhir_error_response(
            format, [code], request_id, [description], 500)
    except:
        code = constants.ACCESS_DENIED
        return handler_utils.create_fhir_error_response(
            format, [code], request_id, ["Unknown Error"], 404)

    response = Response(resp_data)

    handler_utils.add_content_type_header_to_response(format, response)
    log_utils.log_handler_exit(request_id, response.status, constants.SUCCESS)

    return response
예제 #6
0
def get_fhir_role_codes():

    request_id = log_utils.get_request_id(request)
    log_utils.log_handler_entry(request_id, request)

    format, error_description = handler_utils.determine_format(request,
                                                               is_fhir=True)

    if error_description:
        code = constants.INVALID_VALUE_ERROR
        return handler_utils.create_fhir_error_response(
            format, [code], request_id, [error_description], 406)

    valid, descriptions, codes = openods.handlers.handler_utils.isValidFHIRCapabilitiesOrRolesRequest(
        request)
    if not valid:
        return handler_utils.create_fhir_error_response(
            format, codes, request_id, descriptions, 406)

    try:
        response = fhir_roles_service.get_fhir_roles(request_id, format,
                                                     request.base_url)
    except (exception.ServiceError, exception.InvalidDataError):
        description = "Service Unavailable"
        code = constants.ACCESS_DENIED
        return handler_utils.create_fhir_error_response(
            format, [code], request_id, [description], 500)
    except:
        code = constants.ACCESS_DENIED
        return handler_utils.create_fhir_error_response(
            format, [code], request_id, ["Unknown Error"], 404)

    response = Response(response)
    handler_utils.add_content_type_header_to_response(format, response)
    log_utils.log_handler_exit(request_id, response.status, constants.SUCCESS)

    return response
예제 #7
0
def get_organisations():
    """
    Endpoint returning a list of ODS organisations
    ---
    parameters:
      - name: Name
        description: Filters results by names which contain the specified string
        in: query
        type: string
        required: false
      - name: primaryRoleCode
        description: Filters results to only those with one of the specified role codes assigned as a Primary role.
          Ignored if used alongside roleCode parameter.
        in: query
        type: array
        collectionFormat: csv
        required: false
      - name: lastUpdatedSince
        description: Filters results to only those with a lastChangeDate after the specified date.
        in: query
        type: string
        format: date
        required: false
    responses:
      200:
        description: A filtered list of organisation resources
    """
    request_id = log_utils.get_request_id(request)
    log_utils.log_handler_entry(request_id, request)

    format, error_description = handler_utils.determine_format(request,
                                                               is_fhir=False)
    if error_description:
        handler_utils.ord_error_log_and_abort(406, error_description,
                                              request_id)

    valid, description = handler_utils.isValidOrganisationAPIRequest(request)
    if not valid:
        handler_utils.ord_error_log_and_abort(406, description, request_id)

    request_args = ImmutableMultiDict.copy(request.args)
    route = request.base_url

    try:
        resp_data, returned_record_count, total_record_count = \
            ord_organisations_service.get_ord_organisations_summary(request, format, route, request_id)
    except (exception.ServiceError, exception.InvalidDataError):
        handler_utils.ord_error_log_and_abort(500, "Service Unavailable",
                                              request_id)
    except:
        handler_utils.ord_error_log_and_abort(404, "Unknown Error", request_id)

    response = Response(resp_data)

    handler_utils.add_content_type_header_to_response(format, response)

    response.headers['X-Total-Count'] = total_record_count
    response.headers['Access-Control-Expose-Headers'] = 'X-Total-Count'

    if returned_record_count != total_record_count:
        response = create_pagination_headers(request_args, response,
                                             returned_record_count, route,
                                             total_record_count)

    log_utils.log_handler_exit(request_id, response.status, constants.SUCCESS)

    return response