async def add_schedule(schedule: ScheduleScheme, Authorize: AuthJWT = Depends()): """ Takes schedule, adds it to database. :param schedule_id: :return: status """ Authorize.jwt_required() current_role = Repository.get_user_role_by_email(Authorize.get_jwt_subject()) if current_role == 'doctor': ScheduleCollection.insert_obj(dict(schedule)) return {'description': 'Addition successful', 'result': True} return {'description': 'You need to be a doctor', 'result': False}
async def delete_history(history_id: str, Authorize: AuthJWT = Depends()): """ Delete history with id - history_id :param history_id: id of history in the database :return: """ Authorize.jwt_required() current_role = Repository.get_user_role_by_email( Authorize.get_jwt_subject()) if current_role == 'doctor': result, status = Repository.delete_history(history_id) return {'description': result, 'result': status} return {'description': 'You need to be a doctor', 'result': False}
async def get_patients_by_filter(filter: dict, Authorize: AuthJWT = Depends()): """ Get patients list by attributes for search engine. :param filter: dict (column:"value") of attributes to search for. :return: list of patients. """ Authorize.jwt_required() current_role = Repository.get_user_role_by_email(Authorize.get_jwt_subject()) if current_role == 'doctor': patients = Repository.get_patient_by_dict(filter) return {'data': patients, 'result': True} return {'description': 'You need to be a doctor', 'result': False}
async def upload_file(history_id: str, extension: str, request: Request, Authorize: AuthJWT = Depends()): """ upload file to google cloud storage :param history_id: id of history in the database :param extension: name of file :param file_bytes: file to uploading :return: """ Authorize.jwt_required() current_role = Repository.get_user_role_by_email( Authorize.get_jwt_subject()) if current_role == 'doctor': if history_id in HistoriesCollection.get_ids(): if not Repository.get_history_by_id(history_id).get('file_name'): # with open(file.filename, "wb") as buffer: # shutil.copyfileobj(file.file, buffer) # new_filename = str(uuid.uuid4()) + '.' + extension body = b'' async for chunk in request.stream(): body += chunk f = open(new_filename, "wb") f.write(body) f.close() # os.renames(file.filename, new_filename) shutil.move(new_filename, "app/disease_storage/") file_uploader = FileUploader() file_uploader.upload_file( 'app/disease_storage/' + new_filename, new_filename) Repository.update_history(history_id, {'file_name': new_filename}) return {'description': 'Success add file', 'result': True} else: return {'description': 'File already added', 'result': False} return { 'description': 'Can\'n found history by this id', 'result': False } return {'description': 'You need to be a doctor', 'result': False}
async def delete_schedule(schedule_id: str, Authorize: AuthJWT = Depends()): """ Delete schedule by id :param schedule_id: :return: description and status """ Authorize.jwt_required() current_role = Repository.get_user_role_by_email(Authorize.get_jwt_subject()) if current_role == 'doctor': if schedule_id in ScheduleCollection.get_ids(): ScheduleCollection.delete_obj_by_id(schedule_id) return {'description': 'Delete successful', 'result': True} return {'description': 'Can\'t find schedule by this id', 'result': False} return {'description': 'You need to be a doctor', 'result': False}
async def add_history(history: DiseaseHistoryScheme, Authorize: AuthJWT = Depends()): """ Add to database new disease history for user :param history: dict of data to add to database :return: """ Authorize.jwt_required() current_role = Repository.get_user_role_by_email( Authorize.get_jwt_subject()) if current_role == 'doctor': Repository.add_history(history) return {'description': 'Success add', 'result': True} return {'description': 'You need to be a doctor', 'result': False}
def add_new_relative(relative: RelationshipScheme, Authorize: AuthJWT = Depends()): """ Add relative to patient :param relative: object of :return: Json of result about operation """ Authorize.jwt_required() current_role = Repository.get_user_role_by_email( Authorize.get_jwt_subject()) if current_role == 'doctor': Repository.add_relative(relative) return {'description': 'Success add', 'result': True} return {'description': 'You need to be a doctor', 'result': False}
async def update_history(history_id: str, history: DiseaseHistoryScheme, Authorize: AuthJWT = Depends()): """ Update history with id - history_id :param history_id: id of history in the database :param history: dict of data to add to database :return: """ Authorize.jwt_required() current_role = Repository.get_user_role_by_email( Authorize.get_jwt_subject()) if current_role == 'doctor': result, status = Repository.update_history(history_id, history) return {'description': result, 'result': status} return {'description': 'You need to be a doctor', 'result': False}
@router.post('/patients/search/') <<<<<<< HEAD async def get_patients_by_filter(filter: dict, Authorize: AuthJWT = Depends()): ||||||| merged common ancestors async def get_patients_by_dict(filter:dict): ======= async def get_patients_by_filter(filter:dict): >>>>>>> 7502b1f49ac5e4efb7074a3866b964592d53af6b """ Get patients list by attributes for search engine. :param filter: dict (column:"value") of attributes to search for. :return: list of patients. """ Authorize.jwt_required() current_role = Repository.get_user_role_by_email(Authorize.get_jwt_subject()) if current_role == 'doctor': patients = Repository.get_patient_by_dict(filter) return {'data': patients, 'result': True} return {'description': 'You need to be a doctor', 'result': False} @router.get('/patients/') async def get_all_patient(Authorize: AuthJWT = Depends()): """ Get all patients from database :return: list of patients """ Authorize.jwt_required()