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
def get(self, facility_code): fac_info = FacilityModel.objects(facility_code=facility_code).first() if not fac_info: abort(400) def get_average_value(val): return round(val / fac_info.evaluation_count, 1) if fac_info.evaluation_cost != 0 else 0 one_line_e = [e for e in fac_info.one_line_evaluation] return { 'imagePath': fac_info.image_path, 'name': fac_info.name, 'phoneNumber': fac_info.phone_number, 'address': fac_info.address, 'bio': fac_info.bio, 'scoreFacility': get_average_value(fac_info.evaluation_equipment), 'scoreMeal': get_average_value(fac_info.evaluation_meal), 'scoreSchedule': get_average_value(fac_info.evaluation_schedule), 'scoreCost': get_average_value(fac_info.evaluation_cost), 'scoreService': get_average_value(fac_info.evaluation_service), 'overall': get_average_value(fac_info.overall), 'oneLineE': one_line_e[:3] }, 200
def patch(self, facility_code): target = FacilityModel.objects(facility_code=facility_code).first() if not target: abort(400) evaluation = { 'evaluation_equipment': target.evaluation_equipment + request.json['equipment'], 'evaluation_meal': target.evaluation_meal + request.json['meal'], 'evaluation_schedule': target.evaluation_schedule + request.json['schedule'], 'evaluation_cost': target.evaluation_cost + request.json['cost'], 'evaluation_service': target.evaluation_service + request.json['service'], '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)
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)
def post(self): FacilityModel( facility_code=request.json['facilityCode'], name=request.json['name'], phone_number=request.json['phoneNumber'], address=request.json['address'], bio=request.json['bio'], image_path=request.json['imagePath'] ).save() return '', 201
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)
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
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 {}