Пример #1
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)
Пример #2
0
    def get(self, p_id):
        def todays_report(p, date):
            meal = MealMenu.objects(patient=p, date=date).first()
            schedule = Schedule.objects(patient=p, date=date).first()
            photo = RepresentativePhoto.objects(patient=p, date=date).first()
            condition = PhysicalCondition.objects(patient=p, date=date).first()
            additional = AdditionalDescription.objects(patient=p,
                                                       date=date).first()

            return {
                'date':
                str(date),
                'meal': {
                    'breakfast': str(meal.breakfast).split('\n'),
                    'lunch': str(meal.lunch).split('\n'),
                    'dinner': str(meal.dinner).split('\n'),
                    'snack': meal.snack
                } if meal else {},
                'schedule': [{
                    'time': table.start + ' ~ ' + table.end,
                    'work': table.work
                } for table in ScheduleTimeTables.objects(
                    schedule=schedule)] if schedule else [],
                'condition': {
                    k: v
                    for k, v in dict(condition.to_mongo()).items()
                    if type(v) == bool and v is True
                } if condition else {},
                'photo': {
                    'photo_path': photo.image_path,
                    'comment': photo.comment
                } if photo else {},
                'additional': {
                    'description': additional.description
                } if additional else {}
            }

        daughter = DaughterModel.objects(id=get_jwt_identity()).first()
        patient = PatientModel.objects(id=p_id).first()
        current_date = datetime.datetime.utcnow().date()

        if not patient:
            abort(400)

        if patient.daughter.id != daughter.id:
            abort(403)

        return self.unicode_safe_json_dumps(
            {
                'today':
                todays_report(patient, current_date),
                'yesterday':
                todays_report(patient,
                              current_date - datetime.timedelta(days=1)),
                '2days_ago':
                todays_report(patient,
                              current_date - datetime.timedelta(days=2))
            }, 200)
Пример #3
0
    def get(self):
        """
        요양시설의 순위(overall 기준) API
        - 로그인이 되어 있지않다면 순위만 조회할 수 있다.
        - 로그인이 되어있다면 순위와 함께 자신이 이용하고 있는 시설의 정보도 조회할 수 있다.
        - 순위에 표시되는 시설의 정보는 다음과 같다.
            - 시설 이름, 시설 주소, 평가 총점, 칭호(있다면 열거함), 시설 전경(사진)
        """
        def overlap_facility_data(facility_obj):
            return {
                'facilityCode':
                facility_obj.facility_code,
                'imagePath':
                facility_obj.image_path,
                'name':
                facility_obj.name,
                'address':
                facility_obj.address,
                'overall':
                round(facility_obj.overall / facility_obj.evaluation_count, 1)
                if facility_obj.evaluation_count != 0 else None,
                'medals':
                list(facility_obj.medals)
                if facility_obj.medals is not None else []
            } if facility_obj else {}

        # 전체 병원의 순위(overall 기준)
        info = {
            'facilityRanking': [
                overlap_facility_data(facility)
                for facility in FacilityModel.objects.order_by('-overall')
            ]
        }

        # 인증된 사용자라면 사용자 본인이 이용하고 있는 시설의 정보 추가
        if 'Authorization' in request.headers.keys():
            print(request.headers['Authorization'])

            patients = PatientModel.objects(daughter=DaughterModel.objects(
                id=get_jwt_identity()).first())
            cares = [patient.care_worker for patient in patients]
            facs = [
                FacilityModel.objects(
                    facility_code=care.facility_code).first() for care in cares
            ]

            info['myFacilities'] = [overlap_facility_data(fac) for fac in facs]

            # info['myFacilities'] = \
            #     [overlap_facility_data(facility) for facility in
            #      [FacilityModel.objects(facility_code=my_fac.facility_code).first() for my_fac in
            #       [c for c in DaughterModel.objects(id=get_jwt_identity()).first().care_workers]]]

        return self.unicode_safe_json_dumps(info, 200)
Пример #4
0
    def get(self):
        """
        요양 보호사의 순위(overall 기준) API
        - 로그인이 되어 있지않다면 순위만 조회할 수 있다.
        - 로그인이 되어있다면 순위와 함께 자신의 노인을 담당하고 있는 요양보호사의 정보도 조회할 수 있다.
        - 순위에 표시되는 시설의 정보는 다음과 같다.
            - 이름, 소속(요양시설), 담당 노인 수, 경력, 총점
        """
        def overlap_care_worker_data(worker_obj):
            fac = FacilityModel.objects(
                facility_code=worker_obj.facility_code).first()
            return {
                'careWorkerId':
                worker_obj.id,
                'imagePath':
                worker_obj.image_path,
                'name':
                worker_obj.name,
                'workplace':
                fac.name if fac else None,
                'patientInCharge':
                worker_obj.patient_in_charge,
                'career':
                worker_obj.career,
                'overall':
                round(worker_obj.overall / worker_obj.evaluation_count, 1)
                if worker_obj.evaluation_count != 0 else None
            } if worker_obj else {}

        info = {
            'careWorkerRanking': [
                overlap_care_worker_data(care_worker)
                for care_worker in CareWorkerModel.objects.order_by('-overall')
            ]
        }

        if 'Authorization' in request.headers.keys():
            print(request.headers['Authorization'])

            patients = PatientModel.objects(daughter=DaughterModel.objects(
                id=get_jwt_identity()).first())
            cares = [patient.care_worker for patient in patients]

            info['myCareWorkers'] = [
                overlap_care_worker_data(care) for care in cares
            ]
            # info['myCareWorkers'] = [overlap_care_worker_data(care_worker)
            #                          for care_worker
            #                          in DaughterModel.objects(id=get_jwt_identity()).first().care_workers]

        return self.unicode_safe_json_dumps(info, 200)
Пример #5
0
 def get(self):
     daughter = DaughterModel.objects(id=get_jwt_identity()).first()
     return [{
         'id':
         patient.id,
         'name':
         patient.name,
         'careId':
         patient.care_worker.id,
         'careName':
         patient.care_worker.name,
         'facilityCode':
         patient.care_worker.facility_code,
         'facilityName':
         FacilityModel.objects(
             facility_code=patient.care_worker.facility_code).first().name
     } for patient in PatientModel.objects(daughter=daughter)
             if patient.care_worker], 200
Пример #6
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)
Пример #7
0
    def patch(self, p_id):
        memo = request.json['memo']
        PatientModel.objects(id=p_id).first().update(memo=memo)

        return Response('', 201)
Пример #8
0
 def get(self, p_id):
     return PatientModel.objects(id=p_id).first().memo, 200