def create_patient(): name = request.form['name'] sex = request.form['sex'] birth_year = int(request.form['birthYear']) phone_number = request.form['phoneNumber'] provider_id = int(request.form['providerId']) patient = Patient(name=name, birth_year=birth_year, phone_number=phone_number, sex=sex) model.session.add(patient) model.session.commit() photo = request.files['photo'] if photo: # and allowed_file(photo.fileName): # filename = secure_filename(file.filename) filename = "patient_%d_image.jpg" % patient.id photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) patient.photo_filename = filename model.session.commit() provider = Provider.query.get(provider_id) # send_message_helper(patient.name, provider.name, patient.phone_number, message) intro = "Hello %s, this is Dr. %s. " % (patient.name, provider.name) message = "Feel free to send me a message here with your requests/concerns." body_text = intro + message # Send a text message to the number provided sms_message = client.sms.messages.create(to=patient.phone_number, from_=TWILIO_NUMBER, body=body_text) return jsonify(patient=patient.serialize_patient)
def create_new_patient_account(form_data): """Add a patient to the database.""" email = form_data.get("email") dietitian_id = form_data.get("dietitian_id") fname = form_data.get("fname") lname = form_data.get("lname") password = form_data.get("password") street_address = form_data.get("street-address") city = form_data.get("city") state = form_data.get("state") zipcode = form_data.get("zipcode") phone = form_data.get("phone") birthdate = form_data.get("birthdate") new_patient = Patient(dietitian_id=dietitian_id, fname=fname, lname=lname, email=email, street_address=street_address, city=city, state=state, zipcode=zipcode, phone=phone, birthdate=birthdate) new_patient.set_password(password) db.session.add(new_patient) db.session.commit() return new_patient.patient_id
def create(self, **query): # TODO: Check fields if they're correct! if 'birthdate' in query.keys(): query['birthdate'] = datetime.strptime(query['birthdate'], "%Y-%m-%dT%H:%M:%S.%fZ") patient = Patient(**query) try: patient.save() except (FieldDoesNotExist, NotUniqueError, SaveConditionError) as err: message = Message(PatientErrorHeader(message=err.message)) logger.error(err.message) return message patient = self._get_patient(patient.id_patient) self._currentPatient = patient.first() message = Message( PatientCorrectHeader(message='Patient correctly created!'), data=patient) return message
def add_patient(): if 'policy' in request.json: del request.json['policy'] username = request.json['username'] email = request.json['email'] password = request.json['password'] patient = db.session.query(Patient).filter(( Patient.username == username) | (Patient.email == email)).all() provider = db.session.query(Provider).filter(( Provider.username == username) | (Provider.email == email)).all() if not patient and not provider: request.json['password_hash'] = get_hash(password) del request.json['password'] new_patient = Patient(**request.json) db.session.add(new_patient) db.session.commit() return jsonify(new_patient.to_dict()) else: if Patient.query.filter_by( email=email).all() or Provider.query.filter_by( email=email).all(): return jsonify({ 'message': 'email address already registered with an existing account -- registration or login required' }), 409 else: return jsonify({'message': 'username unavailable'}), 409
def test_patient_serialze(self): patient = Patient(id='id', name='name', gender='Male', birth=datetime.datetime.now(), age='1') res = patient.serialize() self.assertEqual(res['id'], 'id') self.assertEqual(res['name'], 'name')
def test_db(): n = random.randint(0, 10000) str = f'abc{n}' p = Patient(name=str) db.session.add(p) db.session.commit() for p in Patient.query.all(): str += p.__repr__() + "<br />" result = Markup(f'<span style="color: green;">Init DB<br />{str}</span>') return render_template('test-patient.html', result=result)
def test_parse_and_convert_modified_patient(): original_dict = db.get_all_patients()[0] parsed_object = Patient.parse(original_dict) # Type: Meeting parsed_object.name = "AASNvlaSNv aknsv laksnvlakvn" original_dict["name"] = "AASNvlaSNv aknsv laksnvlakvn" parsed_dict = parsed_object.to_json_dict() assert original_dict == parsed_dict
def create_patient(fname, lname): """Register a patient.""" new_pat = Patient(fname=fname, lname=lname) db.session.add(new_pat) db.session.commit() return new_pat
def create_dummy(): """Creates dummy data.""" doctor = Doctor(email="*****@*****.**", password="******", name="Miguel", lastName="Fuertes") doctor.id = 1 patient = Patient(doctor=doctor, name='Javier', lastName='Fuertes', gender='male') patient.id = 1 pressure = Pressure(patient, None, 70, 120, 90) weight = Weight(patient, None, 120.6) db.session.add(doctor) db.session.add(patient) db.session.add(pressure) db.session.add(weight) db.session.commit()
def _get_patient(self, id_): """Deprecated""" patient = Patient.objects(id_patient=str(id_)) #TODO: Is there a more elegant way to deal with that? if len(patient) == 0: logger.error('No Patient in the database') return 'ERR' self._currentPatient = patient.first() return patient
def put(self, patientId): token = request.headers.get('X-Auth-Token') if not existsToken(token): resp = Response(status=401) return resp patient = Patient(id=request.json.get('id'), name=request.json.get('name'), gender=request.json.get('gender'), birth=request.json.get('birth'), age=request.json.get('age')) PatientService.ModifyPatient(patientId, patient) return "modify succeed", 204
def load_patients(patient_filename): """Load patients from u.patient into database.""" for row in open(patient_filename): row = row.rstrip() dietitian_id, fname, lname, email, password, street_address, city, state, zipcode, phone, birthdate = row.split( "|") patient = Patient(dietitian_id=dietitian_id, fname=fname, lname=lname, email=email, street_address=street_address, city=city, state=state, zipcode=zipcode, phone=phone, birthdate=birthdate) patient.set_password(password) db.session.add(patient) db.session.commit()
def test_insert(self): patient = Patient("1", "Name", "Last Name", "10/01/2001", "Hombre", "test.dcm", "test.dcm") model.create_patient(patient) patient2 = model.get_patient("1") id = model.find_patient("1") self.assertEqual("1", patient2.id) self.assertEqual("1", id) isChanged = model.set_tagt_result("1", 10, "left") self.assertEqual(True, isChanged) tagt = model.get_tagt_result("1", "left") tagt2 = model.get_tagt_result("1", "right") self.assertEqual(10, tagt) self.assertEqual("", tagt2) model.remove_patient("1")
def make_appointment(): """Add new appointment""" fname = request.form['fname'] lname = request.form['lname'] patient_type = request.form['patient_type'] appointment_time = request.form['appointment_time'] new_patient = Patient(fname=fname, lname=lname, patient_type=patient_type, appointment_time=appointment_time) db.session.add(new_patient) db.session.commit() return redirect('/appointment')
def testInsert(self): patient = Patient("1", "Name", "Last Name", "10/01/2001", "Hombre", "test.dcm", "test.dcm") controller.create_patient(patient) patient2 = controller.get_patient("1") id = controller.findPatient("1") self.assertEqual("1", patient2.id) self.assertEqual("1", id) isChanged = controller.storeTAGTResult(patient, 10, "Izquierda") self.assertEqual(True, isChanged) tagt = controller.getStoredTAGTResult(patient, "Izquierda") tagt2 = controller.getStoredTAGTResult(patient, "Derecha") self.assertEqual(10, tagt) self.assertEqual("", tagt2) controller.removePatient("1")
def post(self): token = request.headers.get('X-Auth-Token') if not existsToken(token): resp = Response(status=401) return resp name = request.json.get('name') gender = request.json.get('gender') birth = request.json.get('birth') age = request.json.get('age') id = uuid.uuid5(uuid.NAMESPACE_DNS, str(datetime.now())) PatientService.createPatient( Patient(id=id, name=name, gender=gender, birth=birth, age=age)) resp = Response(status=201, mimetype='application/json') return resp
def load_pts(): """Load patients from patients into database""" print "Patient" with open('./seed_data/patients.tsv','r+') as data: for i, row in enumerate(data): row = row.rstrip() first_name, last_name,date_of_birth, cell_phone_number, user_name, password = row.split ("\t") patient = Patient( first_name=first_name, last_name=last_name, date_of_birth=date_of_birth, cell_phone_number=cell_phone_number, user_name=user_name, password=password) db.session.add(patient) db.session.commit()
def create_new_pt(first_name, last_name, date_of_birth, cell_phone_number, user_name, password): """This function is to create a new patient""" patient = Patient(first_name=first_name, last_name=last_name, date_of_birth=date_of_birth, cell_phone_number=cell_phone_number, user_name=user_name, password=password) db.session.add(patient) db.session.commit() return patient
def read(self, **query): # TODO: Check query fields! if 'id_patient' in query.keys(): query['id_patient'] = str(query['id_patient']) # return only present patients! query['status'] = 'Attivo' patients = Patient.objects(**query) # Patient list empty if patients.count() == 0: message = Message(PatientNoRecordHeader(), data=patients) logger.error(message.header.message) return message message = Message(PatientCorrectHeader(), data=patients) return message
def create(): user = getUser(get_jwt_identity()) if(('email' in request.form) and ('password' in request.form)): date_time_obj = datetime.strptime(request.form['birthday'], '%d-%m-%Y') try: patientUser=PatientUser( name=request.form['name'], lastName=request.form['lastName'], email=request.form['email'], password=request.form['password'], ) db.session.add(patientUser) db.session.commit() except Exception as error: db.session.flush() db.session.rollback() return jsonify({'result': 'failed', 'data': str(error.orig) + " for parameters" + str(error.params)}) patient = Patient( doctor=user, id=patientUser.id, gender=request.form['gender'], height=request.form['height'], birthday=date_time_obj ) db.session.add(patient) db.session.commit() p_json = JSONTool.object_as_dict(patient) p_json['name'] = patientUser.name p_json['lastName'] = patientUser.lastName p_json['email'] = patientUser.email return jsonify({'result': 'success', 'data': p_json}) else: return jsonify({'result': 'failed', 'detail':'Email and Password are required!'})
def _schedule(self): """Obtains patient info and schedules patient.""" name = raw_input("\nEnter the patient's name: ") condition = self._getCondition() self._model.schedule(Patient(name, condition)) print name, "is added to the", condition, "list\n"
def get_patients_for_doctor(doctor): patients = Patient.gql("WHERE doctor = :doctor ", doctor = doctor).fetch(limit=100000) for patient in patients: complete_patient_tasks(patient) return patients
def get_all_patients(): patients = Patient.all().fetch(limit=10000) for patient in patients: complete_patient_tasks(patient) return patients
def main(): path_to_dataset = "C:\\GIT\\ZIWM\\data.csv" file_writer = FileWriter("") total_number_of_classes = 8 total_number_of_features = 30 num_of_neighbours = [1, 5, 10] type_of_metric = ["euclidean", "manhattan"] #loading raw values from file datasetLoader = load_datasets.Load_datasets(path_to_dataset) dataset_raw_values = datasetLoader.loadDataset() #constructing main dataset with division for features and classes dataset = Dataset(dataset_raw_values) best_fit = 0.0 best_average_fit = 0.0 # selecting number of features and running tests for number_of_features_selected in range(1, 31): #print(number_of_features_selected) trimmed_feature_list = FeatureSelector.selectKBestFeatures( number_of_features_selected, dataset.dataset_features_array, dataset.dataset_class_array) # dividing data sets into patients patients = [] for i in range(len(dataset.dataset_class_array)): patient = Patient(i, dataset.dataset_class_array[i], trimmed_feature_list[i]) # print(patient.getId(), patient.getDisease_class(), patient.get_features()) patients.append(patient) # testing for each metric type and number of neighbours for metric in type_of_metric: for n_neighbours in num_of_neighbours: test_result_arr = [] for i in range(5): print("metric: ", metric, " n_neighbours", n_neighbours, " run: ", i) # creating learn and test data sets learning_set, testing_set = SplitSets.splitSets(patients) # creating algorythm and training kn = KNearestNeighbour(n_neighbours, metric, learning_set, testing_set) kn.train() res1 = kn.test() # swaping training and learning sets temp_set = learning_set learning_set = testing_set testing_set = temp_set kn.setTestSet(testing_set) kn.setTrainingSet(learning_set) # training once again kn.train() res2 = kn.test() print("test result 1: ", res1) print("test result 2: ", res2) test_result_arr.append(res1) test_result_arr.append(res2) if (res1 > best_fit): best_fit = res1 if (res2 > best_fit): best_fit = res2 test_average = sum(test_result_arr) / len(test_result_arr) print("average of tests: ", test_average) result_str = str(number_of_features_selected ) + " | " + metric + " | " + str( n_neighbours) + " | " + str( test_average) + " \n" file_writer.write(result_str) if (test_average > best_average_fit): best_average_fit = test_average # comparing results of test data set # calculating hit rate print("best fit: ", best_fit) print("best fit average: ", best_average_fit) file_writer.close()
def create_patient(first_name, last_name, stu_id, email, phone, emergency, emergency_phone): patient = Patient(first_name, last_name, stu_id, email, phone, emergency, emergency_phone) print patient.patient_info controller.new_patient(patient.patient_info) call_patient_frame_on_top(patient.patient_info)
def test_parse_and_convert_patient(): original_dict = db.get_all_patients()[0] parsed_object = Patient.parse(original_dict) generated_dict = parsed_object.to_json_dict() assert original_dict == generated_dict