Пример #1
0
    def patch(self):
        payload = dict(request.json)
        care = CareWorkerModel.objects(id=get_jwt_identity()).first()

        care.update(**payload)

        return Response('', 201)
Пример #2
0
    def get(self, care_worker_id):
        care_worker = CareWorkerModel.objects(id=care_worker_id).first()

        if not care_worker:
            abort(400)

        def get_average_value(val):
            return round(val / care_worker.evaluation_count,
                         1) if care_worker.evaluation_count != 0 else 0

        one_line_e = [e for e in care_worker.one_line_evaluation]

        fac = FacilityModel.objects(
            facility_code=care_worker.facility_code).first()

        return {
            'imagePath': care_worker.image_path,
            'name': care_worker.name,
            'workplace': fac.name if fac else None,
            'patientInCharge': care_worker.patient_in_charge,
            'career': care_worker.career,
            'bio': care_worker.bio,
            'scoreDiligence':
            get_average_value(care_worker.evaluation_diligence),
            'scoreKindness':
            get_average_value(care_worker.evaluation_kindness),
            'overall': get_average_value(care_worker.overall),
            'oneLineE': one_line_e[:3]
        }, 200
Пример #3
0
    def get(self):
        c = CareWorkerModel.objects(id=get_jwt_identity()).first()
        reqs = RequestModel.objects(care_worker=c)
        patients = PatientModel.objects(care_worker=c)
        data = {
            'connectionRequests': [{
                'req_id': req.req_id,
                'requester_id': req.requester_id,
                'r_name': req.requester_name,
                'p_name': req.patient_name,
                'p_age': req.patient_age,
                'p_gender': req.patient_gender,
                'request_time': req.request_time
            } for req in reqs] if reqs else [],
            'inChargeList': [{
                'd_id': patient.daughter.id,
                'id': patient.id,
                'name': patient.name,
                'age': patient.age,
                'gender': patient.gender,
                'daughter': patient.daughter.name
            } for patient in patients] if patients else []
        }

        return self.unicode_safe_json_dumps(data, 200)
Пример #4
0
    def get(self):
        care = CareWorkerModel.objects(id=get_jwt_identity()).first()

        return self.unicode_safe_json_dumps(
            {
                'profileImage': care.image_path,
                'name': care.name
            }, 200)
Пример #5
0
    def post(self):
        user = CareWorkerModel.objects(id=request.json['id']).first()

        return ({
            'accessToken': create_access_token(user.id),
            'refreshToken': create_refresh_token(user.id)
        }, 200) if user and check_password_hash(
            user.pw, request.json['pw']) else abort(401)
Пример #6
0
    def path(self):
        care = CareWorkerModel.objects(id=get_jwt_identity()).first()

        if not check_password_hash(care.pw, request.json['currentPw']):
            abort(403)

        care.update(pw=request.json['newPw'])

        return Response('', 201)
Пример #7
0
    def get(self):
        care = CareWorkerModel.objects(id=get_jwt_identity()).first()
        patients = PatientModel.objects(care_worker=care)
        patients_list = [str(patient.name)
                         for patient in patients] if patients else []

        return self.unicode_safe_json_dumps(
            {
                'name': care.name,
                'career': care.career,
                'patients': patients_list,
                'facilityCode': care.facility_code,
                'bio': care.bio
            }, 200)
Пример #8
0
    def post(self):
        req_id = str(uuid.uuid4())
        payload = request.json

        RequestModel(
            req_id=req_id,
            care_worker=CareWorkerModel.objects(id=payload['careId']).first(),
            requester_id=payload['requesterId'],
            requester_name=payload['requesterName'],
            patient_name=payload['patientName'],
            patient_age=payload['patientAge'],
            patient_gender=payload['patientGender']
        ).save()

        return Response('', 201)
Пример #9
0
    def get(self):
        name = request.args.get('facilityName')
        facs = FacilityModel.objects(name=re.compile(str('.*' + name + '.*')))

        data = [{
            'facilityCode': fac.facility_code,
            'name': fac.name,
            'address': fac.address,
            'careWorkers': [{
                'id': care.id,
                'name': care.name
            } for care in CareWorkerModel.objects(facility_code=fac.facility_code)]
        } for fac in facs] if facs else []

        return self.unicode_safe_json_dumps(data, 200)
Пример #10
0
    def get(self, p_id):
        current_date = datetime.datetime.utcnow().date()
        care = CareWorkerModel.objects(id=get_jwt_identity()).first()
        patient = PatientModel.objects(id=p_id, care_worker=care).first()

        if not patient:
            abort(400)

        photo = RepresentativePhoto.objects(patient=patient,
                                            date=current_date).first()

        return {
            'photo_path': photo.image_path,
            'comment': photo.comment
        } if photo else {}
Пример #11
0
    def get(self, p_id):
        current_date = datetime.datetime.utcnow().date()
        care = CareWorkerModel.objects(id=get_jwt_identity()).first()
        patient = PatientModel.objects(id=p_id, care_worker=care).first()

        if not patient:
            abort(400)

        schedule = Schedule.objects(patient=patient, date=current_date).first()

        return self.unicode_safe_json_dumps(
            [{
                'time': table.start + ' ~ ' + table.end,
                'work': table.work
            } for table in ScheduleTimeTables.objects(
                schedule=schedule)], 200) if schedule else []
Пример #12
0
    def get(self, p_id):
        current_date = datetime.datetime.utcnow().date()
        care = CareWorkerModel.objects(id=get_jwt_identity()).first()
        patient = PatientModel.objects(id=p_id, care_worker=care).first()

        if not patient:
            abort(400)

        condition = PhysicalCondition.objects(patient=patient,
                                              date=current_date).first()

        return {
            k: v
            for k, v in dict(condition.to_mongo()).items()
            if type(v) == bool and v is True
        } if condition else {}
Пример #13
0
    def get(self, p_id):
        current_date = datetime.datetime.utcnow().date()
        care = CareWorkerModel.objects(id=get_jwt_identity()).first()
        patient = PatientModel.objects(id=p_id, care_worker=care).first()

        if not patient:
            abort(400)

        meal = MealMenu.objects(patient=patient, date=current_date).first()

        return self.unicode_safe_json_dumps(
            {
                'breakfast': str(meal.breakfast).split('\n'),
                'lunch': str(meal.lunch).split('\n'),
                'dinner': str(meal.dinner).split('\n'),
                'snack': meal.snack
            }, 200) if meal else {}
Пример #14
0
    def patch(self):
        def convert_and_save(b64_string, path):
            with open(path, "wb+") as fh:
                fh.write(base64.b64decode(b64_string.encode()))

        care = CareWorkerModel.objects(id=get_jwt_identity()).first()
        image_path = "./static/imgs/care_worker_profiles/" + str(
            care.id) + '.jpg'
        conf = current_app.config

        if os.path.isfile(image_path):
            os.remove(image_path)

        convert_and_save(request.json['encodedImage'], image_path)

        care.update(image_path=conf['HOST'] + ":" + conf['PORT'] +
                    image_path[8:])

        return Response('', 201)
Пример #15
0
    def patch(self):
        accept = request.json['accept']
        requester = DaughterModel.objects(id=request.json['id']).first()
        req = RequestModel.objects(req_id=request.json['reqId']).first()
        myself = CareWorkerModel.objects(id=get_jwt_identity()).first()

        if not requester or not req:
            abort(400)

        if accept:
            PatientModel(id=str(uuid.uuid4()),
                         name=req.patient_name,
                         age=req.patient_age,
                         gender=req.patient_gender,
                         daughter=requester,
                         care_worker=myself).save()

        req.delete()

        return Response('', 201)
Пример #16
0
    def patch(self, care_worker_id):
        target = CareWorkerModel.objects(id=care_worker_id).first()

        if not target:
            abort(400)

        evaluation = {
            'evaluation_diligence':
            target.evaluation_diligence + request.json['diligence'],
            'evaluation_kindness':
            target.evaluation_kindness + request.json['kindness'],
            'overall':
            target.overall + request.json['overall'],
            'evaluation_count':
            1 + target.evaluation_count
        }

        if request.json['lineE']:
            target.one_line_evaluation.append(request.json['lineE'])
            target.save()

        target.update(**evaluation)

        return Response('', 201)
Пример #17
0
    def post(self):
        if not CareWorkerModel.objects(id=get_jwt_identity()).first():
            abort(401)

        return {'accessToken': create_access_token(get_jwt_identity())}, 200