def load_file(): # this should only be called ONCE each time the program runs has_records = False try: with open(my_file, 'r') as load_file: try: json_str = json.load(load_file) has_records = True # no records exist except (ValueError): debug_log('load_file ValueError: no records found') except (FileNotFoundError): choice = input(f"'{my_file}' doesn't exist. create? ").lower() if choice in 'y': debug_log('load_file FileNotFoundError create', my_file) open(my_file, 'w') else: print("quitting") exit(1) if has_records: for object_dict in json_str: Medication(**object_dict)
def loadMedicationFile(file): ''' loads a .medlist file tsv separated by CLASS SUBCLASS GENERIC ''' return_list = [] if not file.endswith('.medlist'): raise FileParseError('%s needs to be a .medlist file\n' % file) with open(file, 'r') as f: for line in f: # comment line, ignore if line.startswith('#'): continue l = [x.strip() for x in line.split('\t')] _class = l[0] _subclass = l[1] _generic = l[2] return_list.append(Medication(_class, _subclass, _generic)) return return_list
def processBatch(a_b): a, b = a_b d = DatastoreClient() p = Patient() e = Encounter() m = Medication() o = Observations() dr = DiagnosticReport() md = MedicationDispense() pr = Procedure() all_patient = sorted(p.all_patient()) for i in range(a, b): if i >= len(all_patient): break id = all_patient[i] getPatientRecords(d, p, e, m, o, dr, md, pr, id) return True
def add_med(): while True: clear_screen() print("creating new medication") # pep8 hates this name_generic = required_ask(str, 'generic name') name_brand = optional_ask(str, 'brand name') dosage = optional_ask(str, 'dosage') doses_per_cycle = required_ask(int, 'take ... dose(s)') cycle_days = required_ask(int, 'every ... day(s)') notes = optional_ask(str, 'notes') new_med = Medication(name_generic, name_brand, dosage, doses_per_cycle, cycle_days, notes) print('created', str(new_med)) if input('add another? ').lower() == 'y': continue break
class PatientTest(unittest.TestCase): def setUp(self): self.patient = Patient() self.medication = Medication("Aspirin") self.patient.add_medication(self.medication) def test_possession_when_full(self): self.medication.add_prescription(Prescription(dispense_date=(date.today() - timedelta(days=30)), days_supply=30)) self.medication.add_prescription(Prescription(dispense_date=(date.today() - timedelta(days=60)), days_supply=30)) self.medication.add_prescription(Prescription(dispense_date=(date.today() - timedelta(days=90)), days_supply=30)) self.assertEquals(90, self.patient.possession([self.medication], 90)) def test_possession_when_partial(self): self.medication.add_prescription(Prescription(dispense_date=(date.today() - timedelta(days=30)), days_supply=30)) self.medication.add_prescription(Prescription(dispense_date=(date.today() - timedelta(days=60)), days_supply=30)) self.assertEquals(60, self.patient.possession([self.medication], 90))
def setUp(self): self.patient = Patient() self.medication = Medication("Aspirin") self.patient.add_medication(self.medication)