def main(): args = get_args() print "Initializing trial." current_week = 0 device_pool = Device_Pool( args.number_of_devices) #Instantiate pool of telemedicine devices. patient_pool = [] #Keep a list of the patients currently recruited. if args.verbose: print_report(current_week, args.number_of_patients, device_pool.get_device_count()) patient_pool.extend([ Patient(device_pool, weeks_with_device=args.weeks_with_device) for x in range(args.recruitment_per_week) ]) #Updates the device pool automatically. args.number_of_patients -= args.recruitment_per_week while args.number_of_patients > 0: #While there are still patients to assign devices to current_week += 1 for patient in patient_pool: patient.pass_week( ) #Automatically returns assigned devices to the pool if the patient is done. patient_pool.extend([ Patient(device_pool, weeks_with_device=args.weeks_with_device) for x in range(args.recruitment_per_week) ]) #Updates the device pool automatically. args.number_of_patients -= args.recruitment_per_week if args.verbose: print_report(current_week, args.number_of_patients, device_pool.get_device_count()) print "Trial completed in {} weeks.\n".format([current_week])
def test_doctor_first(self): d = Doctor("Jack", "Urologist") self.h.on_doctor_called(d) self.assertIsNotNone(self.h.doctors, "The doctor should be waiting for a patient!") p = Patient("Alicia", "Kidney issues") self.h.on_patient_visit(p) self.assertTrue(d.is_with_patient(), "The doctor should be seeing the patient!") self.assertEqual(self.h.patients, [], "There should be no patients in the waiting room!") pp = Patient("Edward", "Kidney issues") self.h.on_patient_visit(pp) self.assertEqual( self.h.patients, [pp], "The new patient should be waiting for the urologist") self.h.on_doctor_called(d) self.assertEqual( self.h.patients, [pp], "The urologist is still with his other patient, " "even though he was called! " "The patient should still be waiting!") self.assertEqual(self.h.doctors, [], "There should be no available doctors!")
def test_patient_doc_match(self): p = Patient("Joe", "Broken arm") d = Doctor("Lil Dicky", "Urologist") c = Doctor("Alicia", "Oncologist") self.h.on_patient_visit(p) self.assertEqual( self.h.patients, [p], "Joe with the broken arm should be in the waiting room!") self.h.on_doctor_called(c) self.h.on_doctor_called(d) self.assertEqual( self.h.doctors, [c, d], "Lil Dicky the urologist should be waiting for a patient!") n = Patient("Suzzy", "Stomach pain") m = Doctor("Alan", "Gastroenterologist") self.h.on_patient_visit(n) self.assertEqual(self.h.patients, [p, n], "There should be two patients in the waiting room!") self.h.on_doctor_called(m) self.assertEqual( self.h.patients, [p], "Suzzy with the stomach pain was help! " "Joe with the broken arm should be waiting!") self.assertEqual( self.h.doctors, [c, d], "Lil Dicky the urologist should be waiting for a patient!") self.assertTrue( m.is_with_patient(), "Alan the gastroenterologist should be helping Suzzy!") a = Doctor("Ian", "Emergency medicine") self.h.on_doctor_called(a) self.assertEqual( self.h.patients, [], "The ER doctor arrived! There should be no one left to help") self.assertEqual( self.h.doctors, [c, d], "Lil Dicky the urologist should be waiting for a patient!") s = Patient("Nate", "Cancer") self.h.on_patient_visit(s) self.assertEqual( self.h.patients, [], "The oncologist is available! There should be no one left to help") self.assertEqual( self.h.doctors, [d], "Lil Dicky the urologist should be waiting for a patient!") ki = Patient("Angela", "Kidney issues") self.h.on_patient_visit(ki) self.assertEqual( self.h.patients, [], "The urologist is available! There should be no one left to help") self.assertEqual(self.h.doctors, [], "All the doctors should be helping people!")
def test_invalid_name(self): with self.assertRaises(ValueError): Patient(1, 1, "A", 1, 3, False, False, True, True, "Jane", "2021-03-18", "2021-03-20", "comment", "twin") with self.assertRaises(ValueError): Patient(1, "", "A", 1, 3, False, False, True, True, "Jane", "2021-03-18", "2021-03-20", "comment", "twin") with self.assertRaises(ValueError): Patient(1, self.long_str, "A", 1, 3, False, False, True, True, "Jane", "2021-03-18", "2021-03-20", "comment", "twin")
def test_invalid_constructor(self): """This method tests invalid constructors of the Patient class.""" with self.assertRaises(TypeError): patient_1 = Patient("Uy", "Tran", "1990-11-20", "1111 Columbia, New Westminster, BC", 2, True, "300", 200000) with self.assertRaises(ValueError): patient_2 = Patient("Uy", "Tran", "1990-11-20", "1111 Columbia, New Westminster, BC", 2, True, 0, 200000)
def test_too_many_patients(self): n = 100 many = [None] * n for i in range(n): many[i] = Patient("SameName", "Kidney issues") for p in many: self.h.on_patient_visit(p) self.assertEqual( self.h.patients, many, "There should be 100 patients waiting for the urologist!") er = Doctor("Mark", "Urologist") self.h.on_doctor_called(er) self.assertTrue( er.is_with_patient(), "The urologist should be seeing one of those 100 patients!") self.assertEqual(self.h.patients, many[1:n], "One of the patients should have been helped!") self.assertEqual( self.h.doctors, [], "There's so many patients to help! The urologist shouldn't be waiting around" ) er.current_patient = None self.assertFalse( er.is_with_patient(), "The urologist finished with a patient and should be free!") for j in range(1, n): self.h.on_doctor_called(er) self.assertTrue( er.is_with_patient(), "The urologist should be seeing one of those 100 patients!") self.assertEqual(self.h.patients, many[j + 1:n], "One of the patients should have been helped!") self.assertEqual( self.h.doctors, [], "There's so many patients to help! The urologist shouldn't be waiting around" ) er.current_patient = None for i in range(n): many[i] = Patient("NotInsured", "Stomach pain", has_insurance=False) for p in many: self.h.on_patient_visit(p) self.assertEqual(self.h.patients, [], "None of those people had insurance!")
def test_patient_insurance(self): p = Patient("Don", "Broken arm") self.h.on_patient_visit(p) self.assertEqual(self.h.patients, [p], "Don should be in the waiting room!") ni = Patient("Kilichan", "Cancer", has_insurance=False) self.h.on_patient_visit(ni) self.assertEqual( self.h.patients, [p], "Kilichan didn't have insurance and was turned away!")
def test_invalid_id(self): """id""" with self.assertRaises(ValueError): Patient("1", "John Doe", "A", 1, 3, False, False, True, True, "Jane", "2021-03-18", "2021-03-20", "comment", "twin") with self.assertRaises(ValueError): Patient(-1, "John Doe", "A", 1, 3, False, False, True, True, "Jane", "2021-03-18", "2021-03-20", "comment", "twin") with self.assertRaises(ValueError): Patient(None, "John Doe", "A", 1, 3, False, False, True, True, "Jane", "2021-03-18", "2021-03-20", "comment", "twin")
def test_get_patients(self): line = PatientsLine() line.add_to_line(Patient("+", 2)) line.add_to_line(Patient("-", 4)) line.add_to_line(Patient("+", 3)) line.add_to_line(Patient("-", 2)) self.assertEqual("+", line.get_next_patient().corona_test_result) self.assertEqual("+", line.get_next_patient().corona_test_result) self.assertEqual("-", line.get_next_patient().corona_test_result) self.assertEqual("-", line.get_next_patient().corona_test_result) self.assertEqual(0, line.get_line_length()) line.add_to_line(Patient("+", 2)) line.add_to_line(Patient("-", 4)) line.add_to_line(Patient("+", 3)) line.add_to_line(Patient("-", 2)) line.elapse_time() line.elapse_time() self.assertEqual("+", line.get_next_patient().corona_test_result) self.assertEqual("-", line.get_next_patient().corona_test_result)
def test_clash_overlapping_today(self): patient = Patient(prescriptions=[Prescription('Codeine', dispense_date = days_ago(days=2), days_supply=2), Prescription('Codeine', dispense_date = days_ago(days=3), days_supply=2)])
def promote_to_patient(self, username, password, age): print("Choose which doctor...") self.list_all_doctors() doctor_id = int(input("Doctor ID:> ")) self.add_patient(username, password, age, doctor_id) patient_id = self.patients_ids[-1] return Patient(username, age, patient_id, doctor_id)
def test_clash_overlaping_today(self): patient = Patient(prescriptions=[ Prescription( "Codeine", dispense_date=days_ago(days=2), days_supply=3), Prescription( "Prozac", dispense_date=days_ago(days=2), days_supply=3) ])
def csv_to_map(csv_file, subject_id, group_by): data = [] with open(csv_file) as csvfile: # reader = csv.reader(csvfile, dialect=csv.excel_tab) reader = read_file(csv_file) data = list(reader) # data[0] contains all the column names data_names = data[0] # column names from data id_index = data[0].index(subject_id) group_index = data[0].index(group_by) # for each patient for row in data[1:]: row_id = row[id_index] row_group = row[group_index] row_data = {} # row_data is map from name of brain region (string) to its value (float) for i in range(0, len(row)): if (data_names[i] in brain_regions): if (isfloat(row[i])): row_data[data_names[i]] = float(row[i]) else: row_data[data_names[i]] = float("inf") # add new patient to patient_map patient_map[row_id] = Patient(row_id, row_group, row_data) # update group's map update_map(row_data, row_group)
def inter_patient_split(n_train_patients, n_val_patients, n_test_patients): patient_ids = [id for id in range(1, 25)] random.shuffle(patient_ids) patients = [ Patient(id) for id in patient_ids[:n_train_patients + n_val_patients + n_test_patients] ] x_train = x_val = x_test = np.zeros((0, 26)) y_train = y_val = y_test = np.array([]) for patient in patients[:n_train_patients]: x_train = np.vstack((x_train, patient.get_eeg_data())) y_train = np.vstack((y_train, patient.get_seizure_labels())) for patient in patients[n_train_patients:n_train_patients + n_val_patients]: x_val = np.vstack((x_val, patient.get_eeg_data())) y_val = np.vstack((y_val, patient.get_seizure_labels())) for patient in patients[n_train_patients + n_val_patients:]: x_test = np.vstack((x_test, patient.get_eeg_data())) y_test = np.vstack((y_test, patient.get_seizure_labels())) return (x_train, y_train), (x_val, y_val), (x_test, y_test)
def test_create_patient(self): Resource_sample = { "resourceType": "Patient", "id": "c1234567890123", "active": True, "identifier": [ { "use": "official", "system": "http://dopa.go.th", "value": "1234567890123" } ], "name": [ { "use": "official", "given": "นาย ก", "family": "นามสมมติ" } ], "birthDate": "2000-01-01", "gender": "male" } p = Patient(1234567890123) p.set_birth_date("2000-01-01") p.set_gender("male") p.set_primary_name("นาย ก", "นามสมมติ") self.assertDictEqual(Resource_sample, p.resource)
def test_one_clash_with_one_prescription(self): patient = Patient(prescriptions=[ Prescription( "Codeine", dispense_date=days_ago(days=2), days_supply=2) ]) self.assertSetEqual( {days_ago(days=2), days_ago(days=1)}, patient.clash(["Codeine"]))
async def new_prescription(ctx, patient: discord.Member): await ctx.send(f"What medication is to be prescribed?") medication = await bot.wait_for("message", check=None) await ctx.send( f"What is the amount of {medication.content} that is to be taken?") amount = await bot.wait_for("message", check=None) await ctx.send("Enter the time to set the patient's reminder.") time_entry = await bot.wait_for("message", check=None) hour, minute = map(int, time_entry.content.split(':')) reminder = datetime.time(hour, minute) await ctx.send(f"Prescription set for {patient.name}!") patientlist[patient.id] = Patient(patient, medication.content, amount.content, reminder) embed = discord.Embed( title="A new prescription reminder has been set for you!", description="Prescription Number", color=0x539cea) embed.set_thumbnail( url="https://image.flaticon.com/icons/png/512/2397/2397639.png") embed.add_field(name="Medication", value=medication.content, inline=True) embed.add_field(name="Amount", value=amount.content, inline=True) embed.add_field(name="Time", value=reminder.strftime("%I:%M %p"), inline=True) await patient.send(embed=embed)
def test_cover_r(self): self.args.tumor_files = ['test/test_normal_1.txt'] self.args.non_tumor_files = ['test/test_normal_1.txt'] self.args.r = 1.5 patient = Patient(self.args, 0) # mean is 2 for C1. self.assertTrue(patient.covers(3.01, 'C1')) self.assertTrue(patient.covers(4, 'C1')) self.assertTrue(patient.covers(100, 'C1')) self.assertFalse(patient.covers(0, 'C1')) self.assertFalse(patient.covers(1, 'C1')) self.assertFalse(patient.covers(2.5, 'C1')) self.assertFalse(patient.covers(3, 'C1')) # mean is 1.25 for C2. self.assertTrue(patient.covers(1.25 * 1.5 + 0.01, 'C2')) self.assertTrue(patient.covers(4, 'C2')) self.assertTrue(patient.covers(100, 'C2')) self.assertFalse(patient.covers(0, 'C2')) self.assertFalse(patient.covers(1, 'C2')) self.assertFalse(patient.covers(1.25, 'C2')) # mean is 3 for C3. self.assertTrue(patient.covers(4.6, 'C3')) self.assertTrue(patient.covers(5, 'C3')) self.assertTrue(patient.covers(100, 'C3')) self.assertFalse(patient.covers(0, 'C3')) self.assertFalse(patient.covers(1, 'C3')) self.assertFalse(patient.covers(1.25, 'C3')) self.assertFalse(patient.covers(3, 'C3')) self.assertFalse(patient.covers(4.5, 'C3'))
def compute(filename_master, filename_corrected, filename_xlsx): data_mat, location_master = readfile_qrsData(filename_master, filename_corrected) data_xlsx, case_coord_data = readfile_xlsx(filename_xlsx) # find_correlation(data_mat, data_xlsx) coorelation = mapping(data_mat, data_xlsx) patient_objects = [] keyset = data_mat.keys() with open('persons.csv', 'w') as csvfile: filewriter = csv.writer(csvfile, delimiter=',') # filewriter.writerow(['PatientID','PacingID','Record','Status','Action']) for patient_id in sorted(keyset): object = Patient(patient_id, list(data_mat[patient_id].keys()), list(data_mat[patient_id].values()), coorelation[patient_id], data_mat[patient_id], data_xlsx, case_coord_data[coorelation[patient_id]], location_master, filewriter) patient_objects.append(object) with open("data.pickle", "wb") as f: pickle.dump(patient_objects, f) f.close() return patient_objects
def test_days_taking_for_irrelevant_prescription(self): patient = Patient(prescriptions=[ Prescription("Paracetamol", dispense_date=date.today() - timedelta(days=2), days_supply=2) ]) assert patient.days_taking("Aspirin") == set()
def create_patient(self): app = App.get_running_app() db = app.DB birthday = "{:02d}".format(int( self.input_birthday_day.text)) + "." + "{:02d}".format( int(self.input_birthday_month.text)) + "." + str( self.input_birthday_year.text) gender = Patient.GENDER_M if not self.checkbox_gender_is_male: gender = Patient.GENDER_F if len(self.input_surname.text) > 0 and len( self.input_first_name.text) > 0 and len( self.input_phone.text) > 0: patient = Patient(db, self.input_surname.text, self.input_first_name.text, birthday, gender, self.input_phone.text) try: patient.save() Factory.PatientCreationSuccessPopup().open() app.root.get_screen(app.root.current).to_home() except Exception as e: print(e) Factory.PatientCreationFailedPopup().open() else: Factory.PatientCreationInputFailedPopup().open()
def test_clash_with_one_irrelevant_prescription(self): patient = Patient(prescriptions=[ Prescription("Paracetamol", dispense_date=date.today() - timedelta(days=2), days_supply=2) ]) assert patient.clash(["Aspirin"]) == set()
def main(argv=None): """main for dicom_dir""" if argv is None: argv = sys.argv args = parse_args(argv=argv[1:]) print(pformat(args)) patients = list() for x in find_dicom_files(directory=args.dicom_dir, pattern="*.dcm", directory_exclude_pattern=".*", recursive=args.recursive): f = pydicom.dcmread(x) for p in patients: try: p.add_dataset(f) except Exception as e: pass else: break else: print("New patient!") patients.append(Patient(dicom_dataset=f)) print("Found", len(patients), "patients") for x in patients: print(repr(x)) print("\n")
def main(): """ Wrapper around the patient class. """ arguments = sys.argv if len(arguments) < 2: print("ERROR: missing argument - %s" % (parser.get_patient_names_string())) return patient_name = arguments[1] if not parser.valid_patient(patient_name): print("ERROR: invalid argument - %s" % (parser.get_patient_names_string())) return # Construct patient using info. from parser. global p p = Patient(patient_name, parser.get_patient_id(patient_name)) p.set_card_path(parser.get_patient_card(patient_name)) contact_info = parser.get_patient_contact_info(patient_name) address = contact_info[ADDRESS] port = contact_info[PORT] # Condition variable for clean termination. cv = Condition() # Create socket object. s = socket.socket() s.bind(('127.0.0.1', port)) print("Socket binded to %s" % (port)) # Put the socket into listening mode. s.listen(5) print("Socket is listening") # Spawn repl thread. print("Starting repl for %s." % (patient_name)) t = Thread(target=repl, args=(s, cv)) t.daemon = True t.start() # Spawn connection thread. t = Thread(target=handle_connection, args=(s, )) t.daemon = True t.start() # Start flask server for frontend t = Thread(target=flask_thread(), args=()) t.daemon = True t.start() # Wait for termination. termination = False cv.acquire() while not termination: cv.wait() termination = True cv.release()
def test_good_patient_id(): p = Patient(123) r = p.get_summary('20121108') assert r['personal info']['first_name'] == 'Jane' assert r['physician info']['first_name'] == 'Enaj' assert r['blood pressure'] != [] assert r['bmi'] != [] assert r['visits'] != []
def prepare_patients(self): """ Prepares data for all patients by reading related files and structuring them as a list of Patient objects :yield: single Patient object """ alias = self.get_aliases() patients_list = [ folder for folder in os.listdir(self.__main_path) if os.path.isdir(os.path.join(self.__main_path, folder)) ] for single_patient in patients_list: index = self.read_test_structure( os.path.join(self.__main_path, single_patient, patient_structure_file), alias) patient_path = os.path.join(self.__main_path, single_patient) # Return image, contour paths and CT tags sorted and of the same length for easier loading image_paths = [ path for path in sorted(os.listdir( os.path.join(patient_path, patient_pngs)), key=my_key) ] if self.__read_contours: contours_paths = [ path for path in sorted(os.listdir( os.path.join(patient_path, patient_contours)), key=my_key) if int(path.split('.')[1]) == index ] # Fill in absent contour files with Nones for i, element in enumerate(image_paths): try: if not contours_paths[i].split( '.')[0] == element.split('.')[0]: contours_paths.insert(i, None) except IndexError: contours_paths.insert(i, None) assert (len(contours_paths) == len(image_paths)) else: contours_paths = [None] * len(image_paths) tags = [ self.read_auxiliary( os.path.join(patient_path, patient_auxiliary, path), ct_tags) for path in sorted(os.listdir( os.path.join(patient_path, patient_auxiliary)), key=my_key) ] assert (len(tags) == len(image_paths)) yield Patient(patient_path, contours_paths, image_paths, tags)
def test_get_description(self): """This one ensures that this method works correctly.""" self.assertTrue(self.patient.is_released()) self.assertEqual(self.patient.get_description(), None) self.patient_1 = Patient("Uy", "Tran", "1990-11-20", "1111 Columbia, New Westminster, BC", 2, False, 300, 200000) self.assertEqual(self.patient_1.get_description(), None)
def test_clash_with_two_prescriptions_for_same_medication(self): patient = Patient(prescriptions=[Prescription('Codeine', dispense_date = days_ago(days=2), days_supply=2), Prescription('Codeine', dispense_date = days_ago(days=3), days_supply=2)]) self.assertSetEqual({days_ago(days=3), days_ago(days=2), days_ago(days=1)}, patient.clash(['Codeine']))
def test_patient_interaction(self): patient = Patient("Don", "Entrepreneur", "Kidney issues") self.assertFalse(self.d.is_with_patient(), "The doctor lied about being with a patient! He said he was with a patient, " "but that's incorrect") self.d.assign_patient(patient) self.assertTrue(self.d.is_with_patient(), "The doctor lied about being with a patient! " "He said he was available when he was with a patient") self.assertEqual(self.d.get_current_patient(), patient, "The doctor lied about the patient he was with!")
def setUp(self): """ creates a test fixture before each test method has run """ self.patient = Patient(1, "John Doe", "A", 1, 3, False, False, True, True, "Jane", "2021-03-18", "2021-03-20", "comment", "twin") self.long_str = "" for i in range(260): self.long_str += "a"