Пример #1
0
def patient_update(request):
    token = request.cookies.get('token')
    if not token:
        return json(get_response(NOT_AUTHORIZED[0], NOT_AUTHORIZED[1]), 401)

    payload = get_payload(token)
    if not payload:
        return json(get_response(NOT_VALID_TOKEN[0], NOT_VALID_TOKEN[1]), 401)

    account_id = payload['id']

    data = request.form

    mistakes = PatientEditSchema().validate(data)
    if mistakes:
        return json(get_response_with_validation_mistakes(mistakes), 400)

    patient = PatientDeserializer.deserialize(data, EDIT_TYPE)
    patient.account.id = account_id

    patient, err = PatientServiceImpl.update(patient)
    if err:
        return json(get_response(err[0], err[1]), 400)

    return json(get_response_with_edit_fields(OK[0], OK[1], list(data.keys())))
Пример #2
0
async def patient_logout(request):
    token = request.cookies.get('token')
    if not token:
        return json(get_response(NOT_AUTHORIZED[0], NOT_AUTHORIZED[1]), 400)

    resp = json(get_response(OK[0], OK[1]))
    del resp.cookies['token']
    return resp
Пример #3
0
async def patient_signup(request):
    data = request.form

    mistakes = SignupSchema().validate(data)
    if mistakes:
        return json(get_response_with_validation_mistakes(mistakes), 400)

    patient = PatientDeserializer.deserialize(data, SIGNUP_TYPE)
    patient, err = PatientServiceImpl.signup(patient)
    if err:
        return json(get_response(err[0], err[1]), 400)

    resp_data = PatientSerializer().serialize(patient, COMMON)
    resp = json(get_response(OK[0], OK[1], data=resp_data))
    resp.cookies['token'] = get_token(patient.account)
    return resp
Пример #4
0
def register_delete(request, register_id):
    token = request.cookies.get('token')
    if not token:
        return json(get_response(NOT_AUTHORIZED[0], NOT_AUTHORIZED[1]), 401)

    payload = get_payload(token)
    if not payload:
        return json(get_response(NOT_VALID_TOKEN[0], NOT_VALID_TOKEN[1]), 401)
    account_id = payload['id']

    register, err = RegisterServiceImpl.delete_my_register(
        register_id, account_id)
    if err:
        return json(get_response(err[0], err[1]), 400)

    return json(get_response(OK[0], OK[1]))
Пример #5
0
def patient_detail(request):
    token = request.cookies.get('token')
    if not token:
        return json(get_response(NOT_AUTHORIZED[0], NOT_AUTHORIZED[1]), 401)

    payload = get_payload(token)
    if not payload:
        return json(get_response(NOT_VALID_TOKEN[0], NOT_VALID_TOKEN[1]), 401)

    account_id = payload['id']
    patient, err = PatientServiceImpl.get_by_account_id(account_id)
    if err:
        return json(get_response(err[0], err[1]), 400)

    resp_data = PatientSerializer().serialize(patient, COMMON)

    return json(get_response(OK[0], OK[1], data=resp_data))
def get_all_free_reception_lines(request):
    token = request.cookies.get('token')
    if not token:
        return json(get_response(NOT_AUTHORIZED[0], NOT_AUTHORIZED[1]), 401)

    payload = get_payload(token)
    if not payload:
        return json(get_response(NOT_VALID_TOKEN[0], NOT_VALID_TOKEN[1]), 401)

    args = request.args
    filter = []
    if args.get('doctor_id') and args.get('doctor_id').isdigit():
        filter.append(('doctor.id = ', int(args.get('doctor_id'))))

    if args.get('service_id') and args.get('service_id').isdigit():
        filter.append(('service.id = ', int(args.get('service_id'))))

    if args.get('service_category_id') and args.get(
            'service_category_id').isdigit():
        filter.append(
            ('service_category.id = ', int(args.get('service_category_id'))))

    if args.get('date_start'):
        filter.append(('date >= ', args.get('date_start')))

    if args.get('date_finish'):
        filter.append(('date <= ', args.get('date_finish')))

    if args.get('time_start'):
        filter.append(('time >= ', args.get('time_start')))

    if args.get('time_finish'):
        filter.append(('time <= ', args.get('time_finish')))

    reception_lines, err = ReceptionLineServiceImpl.get_all_free_by_filter(
        filter)
    if err:
        return json(get_response(err[0], err[1]), 400)

    reception_line_serializer = ReceptionLineSerializer()
    resp_data = [
        reception_line_serializer.serialize(reception_line, COMMON)
        for reception_line in reception_lines
    ]

    return json(get_response(OK[0], OK[1], data=resp_data))
Пример #7
0
def get_all_doctors(request):
    token = request.cookies.get('token')
    if not token:
        return json(get_response(NOT_AUTHORIZED[0], NOT_AUTHORIZED[1]), 401)

    payload = get_payload(token)
    if not payload:
        return json(get_response(NOT_VALID_TOKEN[0], NOT_VALID_TOKEN[1]), 401)

    doctors, err = DoctorServiceImpl.get_all()
    if err:
        return json(get_response(err[0], err[1]), 400)

    resp_data = [
        DoctorSerializer().serialize(doctor, FOR_FILTER) for doctor in doctors
    ]

    return json(get_response(OK[0], OK[1], data=resp_data))
Пример #8
0
def get_all_services(request):
    token = request.cookies.get('token')
    if not token:
        return json(get_response(NOT_AUTHORIZED[0], NOT_AUTHORIZED[1]), 401)

    payload = get_payload(token)
    if not payload:
        return json(get_response(NOT_VALID_TOKEN[0], NOT_VALID_TOKEN[1]), 401)

    services, err = ServiceServiceImpl.get_all()
    if err:
        return json(get_response(err[0], err[1]), 400)

    service_serializer = ServiceSerializer()
    resp_data = [
        service_serializer.serialize(service, FOR_FILTER)
        for service in services
    ]

    return json(get_response(OK[0], OK[1], data=resp_data))
Пример #9
0
def register(request):

    if request.method == 'POST':
        token = request.cookies.get('token')
        if not token:
            return json(get_response(NOT_AUTHORIZED[0], NOT_AUTHORIZED[1]),
                        401)

        payload = get_payload(token)
        if not payload:
            return json(get_response(NOT_VALID_TOKEN[0], NOT_VALID_TOKEN[1]),
                        401)
        account_id = payload['id']

        data = request.form
        mistakes = RegisterSchema().validate(data)
        if mistakes:
            return json(get_response_with_validation_mistakes(mistakes), 400)

        register = RegisterDeserializer.deserialize(data, COMMON)
        register.patient.account.id = account_id
        register, err = RegisterServiceImpl.add(register)
        if err:
            return json(get_response(err[0], err[1]), 400)

        return json(get_response(OK[0], OK[1]))

    elif request.method == 'GET':
        token = request.cookies.get('token')
        if not token:
            return json(get_response(NOT_AUTHORIZED[0], NOT_AUTHORIZED[1]),
                        401)

        payload = get_payload(token)
        if not payload:
            return json(get_response(NOT_VALID_TOKEN[0], NOT_VALID_TOKEN[1]),
                        401)
        account_id = payload['id']

        registers, err = RegisterServiceImpl.get_all_by_account_id(account_id)
        if err:
            return json(get_response(err[0], err[1]), 400)

        register_serializer = RegisterSerializer()
        resp_data = [
            register_serializer.serialize(register, COMMON)
            for register in registers
        ]

        return json(get_response(OK[0], OK[1], data=resp_data))
Пример #10
0
async def patient_restore_password(request):
    return json(get_response(OK[0], OK[1]))