def delete(self, id): try: emergency = EmergencyPetModel.get_by_id(id) emergency.delete() return 'No Content', 204 except Exception as e: return f"{e}", 500
def _list_emergency(self): emergencyPet = EmergencyPetModel.list_all() emergencyPetList = list( map( lambda emergency: { 'id': emergency.id, 'label': emergency.label, 'call': emergency.call, 'lat': emergency.latitude, 'log': emergency.longitude, 'status': emergency.status, 'provider_name': select_provider_by_id(emergency.provider_id)['fantasy_name' ] }, emergencyPet)) emergencyInsured = EmergencyInsuredModel.list_all() emergencyInsuredList = list( map( lambda emergency: { 'id': emergency.id, 'label': emergency.label, 'call': emergency.call, 'lat': emergency.latitude, 'log': emergency.longitude, 'status': emergency.status, 'provider_name': select_provider_by_id(emergency.provider_id)['fantasy_name' ] }, emergencyInsured)) return { 'emergencyPet': emergencyPetList, 'emergencyInsured': emergencyInsuredList }
def select_emergency_pet_by_proposal(proposal_number): proposal = ProposalModel.get_by_number(proposal_number) emergency = EmergencyPetModel.get_by_proposal(proposal.id) pet = PetModel.get_by_proposal(emergency.proposal_id) if emergency.provider_id != 0: provider = ProviderModel.get_by_id(emergency.provider_id) provider_associated = { 'id': provider.id, 'fantasy_name': provider.fantasy_name, 'provider_details': f'http://127.0.0.1:8080/api/user/{provider.user_id}' } else: provider_associated = '' insured_pacient = { 'id': pet.id, 'name': pet.name, 'species': pet.species, 'breed': pet.breed, 'size': pet.size, 'weight': pet.weight, 'proposal': { 'id': proposal.id, 'number': proposal.number, 'status': proposal.status, 'created_date': proposal.created_date.strftime("%d/%m/%Y"), 'plan': select_plan_proposal_by_id(proposal.plan_proposal_id) } } return { 'id': emergency.id, 'label': emergency.label, 'call_type': emergency.call_type, 'call': emergency.call, 'latitude': emergency.latitude, 'longitude': emergency.longitude, 'status_emergency': emergency.status, 'created_date': emergency.created_date.strftime("%d/%m/%Y"), 'provider': provider_associated, 'insured_pacient': insured_pacient }
def _get_emergency(self, id_emergency): emergency = EmergencyPetModel.get_by_id(id_emergency) pet_pacient = select_pet_by_proposal_id(emergency.proposal_id) if emergency is None: return {'message': 'Plan not found'}, 404 return { 'id': emergency.id, 'label': emergency.label, 'call': emergency.call, 'lat': emergency.latitude, 'log': emergency.longitude, 'status': emergency.status, 'provider_name': select_provider_by_id(emergency.provider_id), 'pacient': pet_pacient }
def update_emergency_pet(id, item): try: model = EmergencyPetModel.get_by_id(id) if 'call_type' in item: model.call_type = item['call_type'] if 'call' in item: model.call = item['call'] if 'label' in item: model.label = item['label'] if 'latitude' in item: model.latitude = item['latitude'] if 'longitude' in item: model.longitude = item['longitude'] if 'policy_id' in item: model.policy_id = item['policy_id'] if 'provider_id' in item: model.provider_id = item['provider_id'] if 'collab_id' in item: model.collab_id = item['collab_id'] if 'status' in item: model.status = item['status'] model.save() return {"success": True, "message": 'emergency updated'} except Exception as e: return {"success": False, "message": 'fail update'}
def select_emergency_pet_by_id(id_emergency): emergency = EmergencyPetModel.get_by_id(id_emergency) provider = ProviderModel.get_by_id(emergency.provider_id) provider_associated = { 'id': provider.id, 'fantasy_name': provider.fantasy_name, 'provider_details': f'http://127.0.0.1:8080/api/user/{provider.user_id}' } return { 'id': emergency.id, 'name': emergency.name, 'date': emergency.date, 'time': emergency.time, 'email': emergency.email, 'status_emergency': emergency.status, 'created_date': emergency.created_date.strftime("%d/%m/%Y"), 'provider': provider_associated, 'pet_pacient': select_pet_by_proposal_id(emergency.proposal_id) }
def post(self): item = request.get_json() if request.get_json() else request.form try: model = EmergencyPetModel() model.call = item["call"] model.call_type = item["call_type"] model.latitude = item["lat"] model.longitude = item["log"] model.status = item["status"] model.proposal_id = item["proposal_id"] model.created_date = date.today() model.save() return 201, "created" except Exception as e: return 500, f"nao criado {e}"
def insert_into_emergency_pet(item): try: if item: model = EmergencyPetModel() model.call = item['call'] model.call_type = item['call_type'] model.label = item['label'] model.status = item['status'] model.longitude = item['log'] model.latitude = item['lat'] model.collab_id = item['collab_id'] model.provider_id = item['provider_id'] model.proposal_id = item['proposal_id'] model.save() return 'created', 201 else: return 'not created, invalid payload', 400 except Exception as e: return f"{e}", 500