Ejemplo n.º 1
0
def handle_delete_policy(request, resource_type, resource_id):
    resource = find_latest_resource(resource_type, resource_id, owner_id=request.authorizer.email)
    if resource is None:
        return fhir_error.inform_not_allowed()

    valid, search_elements = fhir_parser.parse_resource(
        resource_type, json.loads(resource.data))
    if not valid:
        return fhir_error.inform_bad_request()

    resource = resource.delete_policy(request.authorizer.email)
    index_resource(resource, search_elements)
    return resource.as_response(request)
Ejemplo n.º 2
0
def handle_create(request, resource_type):
    '''
    handle FHIR create operation
    '''
    correctible = (request.format == 'xml')
    valid, search_elements = fhir_parser.parse_resource(
        resource_type, request.data, correctible)
    if not valid:
        return fhir_error.inform_bad_request()

    resource = Resource(resource_type, request.data, owner_id=request.authorizer.email)
    index_resource(resource, search_elements)

    return resource.as_response(request, created=True)
Ejemplo n.º 3
0
def handle_create(request, resource_type):
    '''
    handle FHIR create operation
    '''
    correctible = (request.format == 'xml')
    valid, search_elements = fhir_parser.parse_resource(
        resource_type, request.data, correctible)
    if not valid:
        return fhir_error.inform_bad_request()

    resource = Resource(resource_type, request.data, owner_id=request.authorizer.email)
    index_resource(resource, search_elements)

    return resource.as_response(request, created=True)
Ejemplo n.º 4
0
def handle_delete_policy(request, resource_type, resource_id):
    resource = find_latest_resource(resource_type,
                                    resource_id,
                                    owner_id=request.authorizer.email)
    if resource is None:
        return fhir_error.inform_not_allowed()

    valid, search_elements = fhir_parser.parse_resource(
        resource_type, json.loads(resource.data))
    if not valid:
        return fhir_error.inform_bad_request()

    resource = resource.delete_policy(request.authorizer.email)
    index_resource(resource, search_elements)
    return resource.as_response(request)
Ejemplo n.º 5
0
def handle_update(request, resource_type, resource_id):
    '''
    handle FHIR update operation
    '''
    old = find_latest_resource(resource_type, resource_id, owner=request.authorizer)
    if old is None:
        return fhir_error.inform_not_allowed()

    correctible = (request.format == 'xml')
    valid, search_elements = fhir_parser.parse_resource(
        resource_type, request.data, correctible)
    if not valid:
        return fhir_error.inform_bad_request()

    new = old.update(request.data)
    index_resource(new, search_elements)

    return new.as_response(request)
Ejemplo n.º 6
0
def handle_update(request, resource_type, resource_id):
    '''
    handle FHIR update operation
    '''
    old = find_latest_resource(resource_type, resource_id, owner=request.authorizer)
    if old is None:
        return fhir_error.inform_not_allowed()

    correctible = (request.format == 'xml')
    valid, search_elements = fhir_parser.parse_resource(
        resource_type, request.data, correctible)
    if not valid:
        return fhir_error.inform_bad_request()

    new = old.update(request.data)
    index_resource(new, search_elements)

    return new.as_response(request)
Ejemplo n.º 7
0
def handle_add_policy(request, resource_type, resource_id):
    resource = find_latest_resource(resource_type, resource_id, owner_id=request.authorizer.email)
    if resource is None:
        return fhir_error.inform_not_allowed()

    correctible = (request.format == 'xml')
    valid, search_elements = fhir_parser.parse_resource(
        resource_type, json.loads(resource.data), correctible)
    if not valid:
        return fhir_error.inform_bad_request()

    if is_policy(request.data):
        resource = resource.add_policy(request.data, request.authorizer.email)
        index_resource(resource, search_elements)
        return resource.as_response(request)

    else:
        return fhir_error.inform_bad_request()
Ejemplo n.º 8
0
def handle_add_policy(request, resource_type, resource_id):
    resource = find_latest_resource(resource_type,
                                    resource_id,
                                    owner_id=request.authorizer.email)
    if resource is None:
        return fhir_error.inform_not_allowed()

    correctible = (request.format == 'xml')
    valid, search_elements = fhir_parser.parse_resource(
        resource_type, json.loads(resource.data), correctible)
    if not valid:
        return fhir_error.inform_bad_request()

    if is_policy(request.data):
        resource = resource.add_policy(request.data, request.authorizer.email)
        index_resource(resource, search_elements)
        return resource.as_response(request)

    else:
        return fhir_error.inform_bad_request()