def get_patients_by_birthdate(patiente_birthdate: datetime, token): current_user: models.Medico = get_current_user_db_with_token(token) patients: list = crud.get_patients_by_date_by_doctor( current_user.id, patiente_birthdate) if not patients: return ServerResponse(ok=False, msg=strings.NOT_PATIENTS, data=[]) return ServerResponse(msg=strings.SUCCESS, data=patients)
def get_consulta_with_patient_by_id(id: int, token): current_user: models.Medico = get_current_user_db_with_token(token) consult = crud.get_consulta_with_patient_by_id(current_user.id, id) if not consult: return ServerResponse(ok=False, msg=strings.CONSULT_NOT_FOUND, data={}) else: return ServerResponse(msg=strings.SUCCESS, data=consult)
def create_cosulta(consulta: shemas.ConsultCreate, token: str): current_user: models.Medico = get_current_user_db_with_token(token) try: crud.create_consulta(consulta, id_doctor=current_user.id) return ServerResponse(msg=strings.CREATED) except: raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=strings.CONSULT_NOT_CREATED)
def create_paciente(pac: shemas.Patient, token: str): current_user: models.Medico = get_current_user_db_with_token(token) try: paciente = models.Paciente.create(**pac.dict(), medico=current_user.id) return ServerResponse(msg=strings.PATIENT_ADED) except: raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=strings.PATIENT_NOT_CREATED)
def delete_multiple(patients: List[shemas.PatientId], token): current_user: models.Medico = get_current_user_db_with_token(token) try: data = crud.delete_multiple_patients_by_doctor(current_user.id, patients) except: raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=strings.ERROR) return ServerResponse(msg=strings.SUCCESS)
def get_pac_by_id(id_patient: int, token): current_user: models.Medico = get_current_user_db_with_token(token) pac = models.Paciente.get_or_none( models.Paciente.id == id_patient, models.Paciente.medico == current_user.id) if pac: return ServerResponse(msg=strings.SUCCESS, data=pac.__data__) else: return ServerResponse(ok=False, msg=strings.NOT_PATIENTS, data={})
def update_photo(doctor:shemas.MedicFoto,token:str): current_user: models.Medico = get_current_user_db_with_token(token) doctor_updated = crud.update_photo(current_user.id, doctor) if doctor_updated ==1: return ServerResponse(msg=strings.DOCTOR_UPDATED) else: raise HTTPException( status_code=status.HTTP_304_NOT_MODIFIED, detail=strings.DOCTOR_NOT_UPDATED)
def update_pac(id_patient: str, pac: shemas.Patient, token): current_user: models.Medico = get_current_user_db_with_token(token) updated = models.Paciente.update(**pac.dict()).where( models.Paciente.id == id_patient, models.Paciente.medico == current_user.id).execute() if updated == 1: return ServerResponse(msg=strings.PATIENT_UPDATED) else: raise HTTPException(status_code=status.HTTP_304_NOT_MODIFIED, detail=strings.PATIENT_NOT_UPDATED)
def delete_pac(id_patient: str, token): current_user: models.Medico = get_current_user_db_with_token(token) dela = models.Paciente.delete().where( models.Paciente.id == id_patient, models.Paciente.medico == current_user.id).execute() if dela == 1: return ServerResponse(msg=strings.PATIENT_DELETED) else: raise HTTPException(status_code=status.HTTP_304_NOT_MODIFIED, detail=strings.PATIENT_NOT_DELETED)
def delete_consulta(id_consult: str, token): current_user: models.Medico = get_current_user_db_with_token(token) dela = models.Consulta.delete().where( models.Consulta.id == id_consult, models.Consulta.medico == current_user.id).execute() if dela == 1: return ServerResponse(msg=strings.CONSULT_DELETED) else: raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=strings.COULD_NOT_DELETE)
def edit_consulta(id_consult, con: shemas.Consult, token): current_user: models.Medico = get_current_user_db_with_token(token) edited = models.Consulta.update(**con.dict()).where( models.Consulta.id == id_consult, models.Consulta.medico == current_user.id).execute() if edited == 1: return ServerResponse(msg=strings.CONSULT_UPDATED) else: raise HTTPException(status_code=status.HTTP_304_NOT_MODIFIED, detail=strings.COULD_NOT_UPDATE)
def get_current_doctor(token:str): current_user: models.Medico = get_current_user_db_with_token(token) current_user_dict:dict = { 'nombre':current_user.nombre, 'apellido':current_user.apellido, 'pais':current_user.pais, 'profesion': current_user.profesion, 'foto':current_user.foto, 'correo':current_user.correo } return ServerResponse(msg=strings.SUCCESS, data=current_user_dict)
def update_password(doctor:shemas.MedicCambiarClave,token:str): current_user: models.Medico = get_current_user_db_with_token(token) if not current_user.clave == doctor.clave: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail=strings.INCORRECT_PASSWORD) doctor_updated = crud.update_password_doctor(current_user.id, doctor.nueva_clave) if doctor_updated ==1: return ServerResponse(msg=strings.DOCTOR_UPDATED) else: raise HTTPException( status_code=status.HTTP_304_NOT_MODIFIED, detail=strings.DOCTOR_NOT_UPDATED)
def update_email_name(doctor:shemas.MedicNombreCorreo,token:str): current_user: models.Medico = get_current_user_db_with_token(token) if check_if_email_is_taken(doctor.correo): raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail= strings.USER_ALRRADY_REGISTERED) doctor_updated = crud.update_email_name_doctor(current_user.id, doctor) if doctor_updated ==1: newToken = Token().encode(current_user.id, doctor.correo) return ServerResponse(msg=strings.DOCTOR_UPDATED, token=newToken) else: raise HTTPException( status_code=status.HTTP_304_NOT_MODIFIED, detail=strings.DOCTOR_NOT_UPDATED)
def get_current_doctor_with_(token:str): current_user: models.Medico = get_current_user_db_with_token(token) consults = crud.get_closset_consults_by_doctor(current_user.id) current_user_consults:dict = { 'nombre':current_user.nombre, 'apellido':current_user.apellido, 'pais':current_user.pais, 'foto':current_user.foto, 'correo':current_user.correo } current_user_consults['fecha_hoy'] = datetime.today() current_user_consults['consults'] = consults if not consults: return ServerResponse(ok=False, msg=strings.NOT_COLSULTS, data=current_user_consults) return ServerResponse(msg=strings.SUCCESS, data=current_user_consults)
def get_all_patient_with_total_visits(token: str): current_user: models.Medico = get_current_user_db_with_token(token) patients: list = crud.get_patients_total_visists_by_doctor(current_user.id) if not patients: return ServerResponse(ok=False, msg=strings.NOT_PATIENTS, data=[]) return ServerResponse(msg=strings.SUCCESS, data=patients)
def get_all_consultas_by_date(token: str, date: datetime): current_user: models.Medico = get_current_user_db_with_token(token) consults = crud.get_all_consults_by_date_by_doctor(current_user.id, date) if not consults: return ServerResponse(ok=False, msg=strings.NOT_COLSULTS, data=[]) return ServerResponse(msg=strings.SUCCESS, data=consults)