async def delete_appointment(conn, request, data): appointment_id = validate_int_values(request.match_info["appointment_id"]) result = await conn.execute( appointment.delete().where(appointment.c.id == appointment_id)) if not result: msg = "Appointment with id: {} does not exists" raise RecordNotFound(msg.format(appointment_id)) return result
async def delete_procedure(conn, request, data): procedure_id = validate_int_values(request.match_info["procedure_id"]) result = await conn.execute( procedure.delete().where(procedure.c.id == procedure_id)) if not result: msg = "Patient with id: {} does not exists" raise RecordNotFound(msg.format(procedure_id)) return result
async def create_procedure(conn, data): result = await conn.execute( procedure.insert().returning(*procedure.c).values( name=data["name"], active=data["active"], )) record = await result.fetchone() if not record: msg = "Patient not created" raise RecordNotFound(msg) return record
async def alter_procedure(conn, request, data): procedure_id = validate_int_values(request.match_info["procedure_id"]) result = await conn.execute(procedure.update().returning( *procedure.c).where(procedure.c.id == procedure_id).values( name=data["name"], active=data["active"], )) record = await result.fetchone() if not record: msg = "Patient with id: {} does not exists" raise RecordNotFound(msg.format(procedure_id)) return record
async def create_appointment(conn, data): validate_date(data) result = await conn.execute( appointment.insert().returning(*appointment.c).values( patient_id=data["patientId"], procedure_id=data["procedureId"], start_date=data["startDate"], end_date=data["endDate"], )) record = await result.fetchall() if not record: msg = "Appointment not created" raise RecordNotFound(msg)
async def alter_appointment(conn, request, data): validate_date(data) appointment_id = validate_int_values(request.match_info["appointment_id"]) result = await conn.execute(appointment.update().returning( *appointment.c).where(appointment.c.id == appointment_id).values( patient_id=data["patientId"], procedure_id=data["procedureId"], start_date=data["startDate"], end_date=data["endDate"], )) record = await result.fetchone() if not record: msg = "Appointment with id: {} does not exists" raise RecordNotFound(msg.format(appointment_id)) return record
async def get_appointment(conn, request): appointment_id = validate_int_values(request.match_info["appointment_id"]) if appointment_id is False: msg = "This is not a valid id for appointment" raise DataTypeError(msg) result = await conn.execute( appointment.select().where(appointment.c.id == appointment_id)) appointment_data = await result.first() if not appointment_data: msg = "Appointment with id: {} does not exists" raise RecordNotFound(msg.format(appointment_id)) return appointment_data
async def get_procedure(conn, request): procedure_id = validate_int_values(request.match_info["procedure_id"]) if procedure_id is False: msg = "This is not a valid id for procedure" raise DataTypeError(msg) result = await conn.execute( procedure.select().where(procedure.c.id == procedure_id)) procedure_data = await result.first() if not procedure_data: msg = "Patient with id: {} does not exists" raise RecordNotFound(msg.format(procedure_id)) return dict(procedure_data.items())
async def create_patient(conn, data): result = await conn.execute( patient.insert() .returning(*patient.c) .values( first_name=data["firstName"], last_name=data["lastName"], cpf=data["cpf"].replace("-", "").replace(".", ""), date_of_birth=data["dateOfBirth"], gender=data["gender"], active=data["active"], ) ) record = await result.fetchone() if not record: msg = "Patient not created" raise RecordNotFound(msg) return record
async def alter_patient(conn, request, data): patient_id = validate_int_values(request.match_info["patient_id"]) result = await conn.execute( patient.update() .returning(*patient.c) .where(patient.c.id == patient_id) .values( first_name=data["firstName"], last_name=data["lastName"], cpf=data["cpf"], date_of_birth=data["dateOfBirth"], gender=data["gender"], active=data["active"], ) ) record = await result.fetchone() if not record: msg = "Patient with id: {} does not exists" raise RecordNotFound(msg.format(patient_id)) return record