def notifyNearbyUsers(json, user): if(json['test_status']==3): visited_locations = VisitedLocation.getLocationsVisitedByUserId(json['patient_id']) for patient_visited_location in visited_locations: patient_location = Utilities.to_dict(Location.getLocationById(patient_visited_location.location_id)) patient_location['lattitude'] = float("{:.14f}".format(patient_location['lattitude'])) patient_location['longitude'] = float("{:.14f}".format(patient_location['longitude'])) locations_within_1km = Location.getLocationsWithinOneKilometerRadius(patient_location) for close_location in locations_within_1km: locations_in_danger = VisitedLocation.getVisitedLocationByLocationId(close_location.location_id) for user_visited_location in locations_in_danger: user_in_danger = Utilities.to_dict(User.getUserById(user_visited_location.user_id)) if user_in_danger['user_id'] != user['user_id'] and patient_visited_location.date_visited == user_visited_location.date_visited: msg = Message('Possible COVID-19 Contact', sender='*****@*****.**', recipients=[user_in_danger['email']]) msg.body = f'''Hi {user_in_danger['full_name']}, An indivual that tested positive to COVID-19 visited location @ lattitude: {patient_location['lattitude']}, @longitude: {patient_location['longitude']}. in the day of {patient_visited_location.date_visited}. It looks like you visited a location within 1 km of distance, so you might have been exposed to the COVID-19. If you don't feel well in the following days, get tested. For the offices that provides COVID-19 test, please check our website.''' mail.send(msg)
def getLocationById(lid): try: location = Location.getLocationById(lid) location_dict = Utilities.to_dict(location) result = {"message": "Success!", "location": location_dict} return jsonify(result), 200 except Exception as e: return jsonify(reason="Server error", error=e.__str__()), 500