Пример #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)
Пример #2
0
    def updateRecord(json):
        valid_parameters = Utilities.verify_parameters(json, CovidCases.REQUIRED_PARAMETERS)
        if valid_parameters:
            try:
                updatedInfo = CovidCases.updateCovidStatus(json)
                result = {
                    "message": "Success!",
                    "case": Utilities.to_dict(updatedInfo)
                }

                user = Utilities.to_dict(User.getUserById(json['patient_id']))
                office = Utilities.to_dict(MedicalOffice.getMedicalOfficeById(json['office_id']))

                statuses = {2: 'negative', 3: 'positive'}

                msg = Message('COVID-19 Test Result',
                                sender='*****@*****.**',
                                recipients=[user['email']])
                msg.body = f'''Hi {user['full_name']},

                    Your tested {statuses[json['test_status']]} to the COVID-19. If you want to know more info about your COVID-19 test, please call {office['office_phone_number']}.
                    '''
                mail.send(msg)

                CovidCasesHandler.notifyNearbyUsers(json, user)          

                return jsonify(result), 200
            except Exception as e:
                return jsonify(reason="Server error", error=e.__str__()), 500
 def register(json):
     validParams = Utilities.verify_parameters(json, [
         'username', 'email', 'password', 'first_name', 'last_name', 'role'
     ])
     validParams['role'] = 'customer'
     checkUsername = Users.getUserByUsername(validParams['username'])
     checkUserEmail = Users.getUserByEmail(validParams['email'])
     if validParams:
         try:
             if checkUsername != None:
                 return jsonify(reason="Username already exists!")
             elif checkUserEmail != None:
                 return jsonify(reason="Email already exists!")
             elif not re.match(r'[a-zA-Z0-9]+', validParams['username']):
                 return jsonify(
                     reason=
                     "Username must contain only characters and numbers")
             elif not re.match(r'[^@]+@[^@]+\.[^@]+', validParams['email']):
                 return jsonify(reason="Invalid email address")
             newUser = Users(**validParams).create()
             result = {
                 "message": "Success!",
                 "request": Utilities.to_dict(newUser)
             }
             return jsonify(result), 200
         except Exception as e:
             return jsonify(reason="Server error", error=e.__str__()), 500
     else:
         return jsonify(reason="Invalid parameters"), 400
 def deleteDoctor(oid, uid):
     deletedDoctor = Doctor.deleteDoctor(oid, uid)
     result = {
         "message": "Success!",
         "patient": Utilities.to_dict(deletedDoctor)
     }
     return jsonify(result), 200
 def businessRegister(json):
     validParams = Utilities.verify_parameters(json, [
         'business_name', 'address', 'city', 'zip_code', 'business_email',
         'business_phone', 'max_capacity', 'owner_id', 'service_id'
     ])
     if validParams:
         try:
             if not re.match(r'[A-Za-z0-9]+', validParams['business_name']):
                 return jsonify(
                     reason=
                     "Business name must contain only characters and numbers"
                 )
             if not re.match(r'[^@]+@[^@]+\.[^@]+',
                             validParams['business_email']):
                 return jsonify(reason="Invalid email address")
             elif not re.search(r'\w{3}-\w{3}-\w{4}',
                                validParams['business_phone']):
                 return jsonify(
                     reason="The format for business phone is: ###-###-####"
                 )
             elif not re.match(r'[0-9]{5}', validParams['zip_code']):
                 return jsonify(reason="The format for zip code is: #####")
             elif not re.match(r'[0-9]', validParams['max_capacity']):
                 return jsonify(reason="Max capacity must be a number")
             Users.updateRole(validParams['owner_id'])
             newBusiness = Businesses(**validParams).create()
             result = {
                 "message": "Success!",
                 "request": Utilities.to_dict(newBusiness)
             }
             return jsonify(result), 200
         except Exception as e:
             return jsonify(reason="Server error", error=e.__str__()), 500
     else:
         return jsonify(reason="Invalid parameters"), 400
 def getPatientByOfficeAndUserId(oid, uid):
     try:
         patient = Patient.getPatientByOfficeAndUserId(oid, uid)
         patient_dict = Utilities.to_dict(patient)
         result = {"message": "Success!", "patient": patient_dict}
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
 def getUserByEmail(uemail):
     try:
         user = Users.getUserByEmail(uemail)
         user_dict = Utilities.to_dict(user)
         result = {"message": "Success!", "users": user_dict}
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
Пример #8
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
 def getBusinessByOwner(uid):
     try:
         business = Businesses.getBusinessByOwner(uid)
         business_dict = Utilities.to_dict(business)
         result = {"message": "Success!", "business": business_dict}
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
 def getApptById(aid):
     try:
         appt = Appointment.getApptById(aid)
         appt_dict = Utilities.to_dict(appt)
         result = {"message": "Success!", "appointment": appt_dict}
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
Пример #11
0
 def deleteVisitedLocation(uid, lid, date):
     deletedVisitedLocation = VisitedLocation.deleteVisitedLocation(
         uid, lid, date)
     result = {
         "message": "Success!",
         "visited_location": Utilities.to_dict(deletedVisitedLocation)
     }
     return jsonify(result), 200
 def getAllUsers():
     try:
         users = Users.getUsers()
         users_list = []
         for user in users:
             users_list.append(Utilities.to_dict(user))
         result = {"message": "Success!", "users": users_list}
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
 def getAllDoctors():
     try:
         doctors = Doctor.getAllDoctors()
         result_list = []
         for doctor in doctors:
             result_list.append(Utilities.to_dict(doctor))
         result = {"message": "Success!", "doctors": result_list}
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
 def getDoctorByUserId(did):
     try:
         doctors = Doctor.getDoctorByUserId(did)
         result_list = []
         for doctor in doctors:  #let's not get consfuse, sometimes doctors may work in mort than one ficcw
             result_list.append(Utilities.to_dict(doctor))
         result = {"message": "Success!", "doctor": result_list}
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
 def getAllAppointments():
     try:
         appointments = Appointment.getAppointments()
         appt_list = []
         for appt in appointments:
             appt_list.append(Utilities.to_dict(appt))
         result = {"message": "Success!", "appointments": appt_list}
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
Пример #16
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
Пример #17
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
 def getAllBusinesses():
     try:
         businesses = Businesses.getBusinesses()
         businesses_list = []
         for business in businesses:
             businesses_list.append(Utilities.to_dict(business))
         result = {"message": "Success!", "businesses": businesses_list}
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
 def getPatientsByOfficeId(oid):
     try:
         patients = Patient.getPatientsByOfficeId(oid)
         result_list = []
         for patient in patients:
             result_list.append(Utilities.to_dict(patient))
         result = {"message": "Success!", "patients": result_list}
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
Пример #20
0
 def getUserByEmail(email):
     try:
         user = User.getUserByEmail(email)
         if user:
             user_dict = Utilities.to_dict(user)
             result = {"message": "Success!", "user": user_dict}
             return jsonify(result), 200
         else:
             return jsonify(reason="User does not exist."), 401
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
 def getServiceById(sid):
     try:
         service = Services.getServiceById(sid)
         service_dict = Utilities.to_dict(service)
         result = {
             "message": "Success!",
             "services": service_dict
         }
         return jsonify(result), 200
     except Exception as e:
         return jsonify(message="Server error", error=e.__str__()), 500   
Пример #22
0
 def deleteRecord(key):
     try:
         parameters = key.split('&')
         deleted_record = CovidCases.deleteRecord({'patient_id': parameters[0], 'office_id': parameters[1], 'date_tested': parameters[2]})
         result = {
             "message": "Success!",
             "case": Utilities.to_dict(deleted_record)
         }
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
 def userRegisterAppt(aid, uid):
     validParams = Utilities.verify_parameters(json,
                                               ['number_of_customers'])
     try:
         appt = Appointment.updateAppt(aid, uid)
         result = {
             "message": "Success!",
             "request": Utilities.to_dict(appt)
         }
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
 def deletePatient(oid, uid):
     covid_case_exists = CovidCases.getCasesByPatientId(uid)
     if covid_case_exists:
         return jsonify(
             reason="Can't delete the patient, the patient has active tests."
         ), 400
     deletedPatient = Patient.deletePatient(oid, uid)
     result = {
         "message": "Success!",
         "patient": Utilities.to_dict(deletedPatient)
     }
     return jsonify(result), 200
Пример #25
0
    def getVisitedLocationsRelativeToAddress(aid):
        try:
            visited_locations = VisitedLocation.getVisitedLocationsRelativeToAddress(
                aid)
            result_list = []
            for location in visited_locations:
                result_list.append(Utilities.to_dict(location))

            result = {"message": "Success!", "visited_locations": result_list}
            return jsonify(result), 200

        except Exception as e:
            return jsonify(reason="Server error", error=e.__str__()), 500
Пример #26
0
 def getCovidTestsByDoctorId(did):
     try:
         records = CovidCases.getCasesByDoctorId(did)
         result_list = []
         for record in records:
             result_list.append(Utilities.to_dict(record))
         result = {
             "message": "Success!",
             "cases": result_list
         }
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
Пример #27
0
 def getNegativeTests():             #includes the patients who have never being infected and those that recovered
     try:
         negative_records = CovidCases.getNegativeCases()
         result_list = []
         for record in negative_records:
             result_list.append(Utilities.to_dict(record))
         result = {
             "message": "Success!",
             "cases": result_list
         }
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
Пример #28
0
 def getCumulativePositiveCases():
     try:
         positive_records = CovidCases.getCumulativePositiveCases()
         result_list = []
         for record in positive_records:
             result_list.append(Utilities.to_dict(record))
         result = {
             "message": "Success!",
             "cases": result_list
         }
         return jsonify(result), 200
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), 500
 def getAllServices():
     try:
         services = Services.getServices()
         service_list = []
         for svc in services:
             service_list.append(Utilities.to_dict(svc))
         result = {
             "message": "Success!",
             "services": service_list
         }
         return jsonify(result), 200
     except Exception as e:
         return jsonify(message="Server error", error=e.__str__()), 500
    def getMedicalOfficeByAddressId(aid):
        try:
            medical_office = MedicalOffice.getMedicalOfficeByAddressId(aid)
            medical_dict = Utilities.to_dict(medical_office)

            result = {
                "message": "Success!",
                "medical_office": medical_dict
            }

            return jsonify(result), 200

        except Exception as e:
            return jsonify(reason="Server error", error=e.__str__()), 500