Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 def getLocationsRelativeToAddress(aid):
     try:
         location = Location.getLocationsRelativeToAddress(aid)
         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
Exemplo n.º 3
0
    def getLocationByLattitudeAndLongitude(json):
        try:
            location = Location.getLocationByLattitudeAndLongitude(json)
            location_dic = Utilities.to_dict(location)

            result = {"message": "Success!", "location": location_dic}
            return jsonify(result), 200

        except Exception as e:
            return jsonify(reason="Server error", error=e.__str__()), 500
Exemplo n.º 4
0
 def getAllLocations():
     try:
         locations = Location.getAllLocations()
         result_list = []
         for location in locations:
             result_list.append(Utilities.to_dict(location))
         result = {"message": "Success!", "locations": result_list}
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
Exemplo n.º 5
0
    def createLocation(json):
        valid_params = Utilities.verify_parameters(
            json, Location.REQUIRED_PARAMETERS)
        if valid_params:
            try:
                location = Location.getLocationByLattitudeAndLongitude(json)

                if location == None:
                    location = Location(**valid_params).create()

                location_dict = Utilities.to_dict(location)

                result = {
                    "message": "Success!",
                    "location": location_dict,
                }
                return jsonify(result), 201
            except Exception as err:
                return jsonify(message="Server error!",
                               error=err.__str__()), 500
        else:
            return jsonify(message="Bad Request!"), 40