Exemplo n.º 1
0
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}
Exemplo n.º 2
0
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}
Exemplo n.º 3
0
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}
Exemplo n.º 4
0
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}
Exemplo n.º 5
0
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}
Exemplo n.º 6
0
async def delete_file(history_id: str):
    filename = Repository.get_history_by_id(history_id).get('file_name')

    if filename:
        file_uploader = FileUploader()

        if filename in file_uploader.list_blobs():
            file_uploader.delete_file(filename)
        else:
            Repository.update_history(history_id, {'file_name': None})
            return {"description": "File not found", 'result': False}

        Repository.update_history(history_id, {'file_name': None})
        return {"description": "File was successful deleted", 'result': True}

    return {"description": "File not found", 'result': False}
Exemplo n.º 7
0
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}
Exemplo n.º 8
0
async def get_all_hospitals(Authorize: AuthJWT = Depends()):
    """
    Get all hospitals from database
    :return: list of hospitals
    """
    Authorize.jwt_required()
    list_hospitals = Repository.get_all_hospitals()

    return {'data': list_hospitals, 'result': bool(list_hospitals)}
Exemplo n.º 9
0
async def get_hospital_profile(hospital_id: str,
                               Authorize: AuthJWT = Depends()):
    """
    Get data for hospital profile
    """
    Authorize.jwt_required()
    hospital_profile = Repository.get_hospital_by_id(hospital_id)

    return {'data': hospital_profile, 'result': bool(hospital_profile)}
Exemplo n.º 10
0
async def get_schedule(doctor_id: str, Authorize: AuthJWT = Depends()):
    """
    Get doctor's all schedules by id
    :param doctor_id:
    :return: schedule_data
    """
    Authorize.jwt_required()
    result = Repository.get_schedule(doctor_id)

    return result
Exemplo n.º 11
0
async def get_all_doctors(Authorize: AuthJWT = Depends()):
    """
    Get all doctors from database

    :return: list of doctors
    """
    Authorize.jwt_required()
    list_doctors = Repository.get_all_doctors()

    return {'data': list_doctors, 'result': bool(list_doctors)}
Exemplo n.º 12
0
async def get_history(history_id: str, Authorize: AuthJWT = Depends()):
    """
    Get history of some patient with some id of history
    :param history_id: id of history in the database
    :return: histories with history_id
    """
    Authorize.jwt_required()
    history = Repository.get_history_by_id(history_id)

    return {'data': history, 'result': bool(history)}
Exemplo n.º 13
0
def get_relatives_of_patient(user_id: str, Authorize: AuthJWT = Depends()):
    """
    Get all relatives of patient
    :param user_id: user_id of patient, whose relatives we're looking
    :return:
    """
    Authorize.jwt_required()
    relatives = Repository.get_relatives(user_id)

    return {'data': relatives, 'result': bool(relatives)}
Exemplo n.º 14
0
async def get_all_patient(Authorize: AuthJWT = Depends()):
    """
    Get all patients from database

    :return: list of patients
    """
    Authorize.jwt_required()
    list_patients = Repository.get_all_patients()

    return {'data': list_patients, 'result': bool(list_patients)}
Exemplo n.º 15
0
async def add_appointment(appointment: AppointmentScheme,
                          Authorize: AuthJWT = Depends()):
    """
    Adds an appointment of patient with a doctor
    :param appointment: dictionary containing appointment details
    :return: status
    """
    Authorize.jwt_required()
    status = Repository.add_appointment(appointment)
    return status
Exemplo n.º 16
0
async def get_appointments_by_doctor(doctor_id: str,
                                     Authorize: AuthJWT = Depends()):
    """
    Returns a list of appointments given doctor_id
    :param doctor_id: doctor id
    :return: list of appointments
    """
    Authorize.jwt_required()
    appointments = Repository.get_appointments_by_doctor(doctor_id)

    return appointments
Exemplo n.º 17
0
async def get_patient_profile(user_id: str, Authorize: AuthJWT = Depends()):
    """
    Get data for patients profile

    :param user_id: Id of user in database
    :return: patient data
    """
    Authorize.jwt_required()
    patient_profile = Repository.get_patient_by_id(user_id)

    return {'data': patient_profile, 'result': bool(patient_profile)}
Exemplo n.º 18
0
async def get_doctors_by_filter(filter: dict, Authorize: AuthJWT = Depends()):
    """
    Get doctors list by features for search engine.

    :param filter: dict (column:"value") of features to search for.
    :return: list of found doctors.
    """
    Authorize.jwt_required()
    list_doctors = Repository.get_doctor_by_dict(filter)

    return list_doctors
Exemplo n.º 19
0
async def get_disease_histories(patient_id: str,
                                Authorize: AuthJWT = Depends()):
    """
    Get list of disease histories of some user
    :param patient_id:
    :return: list of histtories
    """
    Authorize.jwt_required()
    histories_patient = Repository.get_histories_by_patient_id(patient_id)

    return {'data': histories_patient, 'result': bool(histories_patient)}
Exemplo n.º 20
0
 def within_working_hours(cls, v, values):
     schedule = Repository.get_schedule(values['doctor_id'])['data']
     workingHours = [(s['startTime'], s['finishTime']) for s in schedule
                     if s['weekDay'] == v.strftime('%A')
                     ]  # get working hours on the appointment day
     v = v.replace(tzinfo=None)
     for start, finish in workingHours:
         if start.time() <= v.time() <= finish.time():
             return v
     raise ValueError(
         f'Out of schedule! Doctor is working today at {workingHours}')
Exemplo n.º 21
0
async def get_appointments_by_filter(filter: dict,
                                     Authorize: AuthJWT = Depends()):
    """
    Returns a list of appointments given filter
    :param filter: dictionary of what to search for
    :return: appointments list
    """
    Authorize.jwt_required()
    appointments = Repository.get_appointments_by_filter(filter)

    return appointments
Exemplo n.º 22
0
async def delete_appointment(appointment_id: str,
                             Authorize: AuthJWT = Depends()):
    """
    Deletes an appointment with given id
    :param id: _id of the appointment
    :return: status
    """
    Authorize.jwt_required()
    status = Repository.delete_appointment(appointment_id)

    return status
Exemplo n.º 23
0
async def get_hospitals_doctors(hospital_id: str,
                                Authorize: AuthJWT = Depends()):
    """
    Get doctors of hospital with hospital_id
    :param hospital_id: hospital's id
    :return: list of doctors
    """
    Authorize.jwt_required()
    list_doctors = Repository.get_doctors_by_hospital_id(hospital_id)

    return {'data': list_doctors, 'result': bool(list_doctors)}
Exemplo n.º 24
0
async def get_doctor_profile(user_id: str, Authorize: AuthJWT = Depends()):
    """
    Get data for doctor's profile

    :param user_id: Id of doctor in database
    :return: doctor data
    """
    Authorize.jwt_required()
    doctor_profile = Repository.get_doctor_by_id(user_id)

    return {'data': doctor_profile, 'result': bool(doctor_profile)}
Exemplo n.º 25
0
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}
Exemplo n.º 26
0
 def is_unoccupied(cls, values):
     if 'startDateTime' in values and 'finishDateTime' in values:
         values['startDateTime'] = values['startDateTime'].replace(
             tzinfo=None)
         values['finishDateTime'] = values['finishDateTime'].replace(
             tzinfo=None)
         doctors_appointments = Repository.get_appointments_by_doctor(
             values['doctor_id'])
         for a in doctors_appointments:
             if a['startDateTime'] <= values['startDateTime'] <= a[
                     'finishDateTime'] or a['startDateTime'] <= values[
                         'finishDateTime'] <= a['finishDateTime']:
                 raise ValueError('Time overlaps with existing appointment')
     return values
Exemplo n.º 27
0
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}
Exemplo n.º 28
0
async def get_analytics():
    """
    Get data for analytics
    """
    histories = Repository.get_all_histories()

    illness_count = dict()
    status_count = dict()
    for history in histories:
    	status_count[history['status']] = status_count.get(history['status'], 0) + 1
    	illness_count[history['diagnosis']] = illness_count.get(history['diagnosis'], 0) + 1
    data = {
    	'illness_count': illness_count,
    	'status_count': status_count
    }

    return {'data': data, 'result': bool(histories)}
Exemplo n.º 29
0
async def download_file(history_id: str, Authorize: AuthJWT = Depends()):
    Authorize.jwt_required()
    if history_id in HistoriesCollection.get_ids():
        filename = Repository.get_history_by_id(history_id).get('file_name')

        if filename not in os.listdir(CLEARED_DIR):
            file_uploader = FileUploader()

            if filename in file_uploader.list_blobs():
                file_uploader.download_file(filename)
            else:
                return {'description': "File not found", 'result': True}

            shutil.move(filename, "app/disease_storage/")

        return FileResponse('app/disease_storage/' + filename,
                            media_type='application/octet-stream',
                            filename=filename)

    return {'description': 'Can\'n found history by this id', 'result': False}
Exemplo n.º 30
0
@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()