def getActiveCases(): try: patients = Patient.getAllPatients() active_cases = [] for patient in patients: case = CovidCases.getMostRecentCaseByPatient(patient.user_id) if case.test_status == 3: active_cases.append(Utilities.to_dict(case))
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 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 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
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
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
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 getRecoveredCases(): try: patients = Patient.getAllPatients() recovered_cases = [] for patient in patients: cases = CovidCases.getCasesByPatientId(patient.user_id) prev_case = None for patient_case in cases: if patient_case.test_status != 3 and prev_case and prev_case.test_status == 3: recovered_cases.append(Utilities.to_dict(patient_case)) prev_case = patient_case result = { "message": "Success!", "cases": recovered_cases } return jsonify(result), 200 except Exception as e: return jsonify(reason="Server error", error=e.__str__()), 500
def createRecord(json): valid_params = Utilities.verify_parameters(json, CovidCases.REQUIRED_PARAMETERS) if valid_params: try: patient_exists = Patient.getPatientByOfficeAndUserId(json['office_id'], json['patient_id']) if patient_exists: try: covid_case = CovidCases(**valid_params).create() case_dict = Utilities.to_dict(covid_case) result = { "message": "Success!", "case": case_dict, } return jsonify(result), 201 except: return jsonify(reason="Patient was already tested today."), 401 else: return jsonify(reason="User is not in our office record."), 401 except Exception as err: return jsonify(message="Server error!", error=err.__str__()), 500 else: return jsonify(message="Bad Request!"), 40