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 test_initial_dispense_date(self):
     self.medicine.add_prescription(
         Prescription(dispense_date=date(2009, 11, 1), days_supply=30))
     self.medicine.add_prescription(
         Prescription(dispense_date=date(2009, 11, 30), days_supply=30))
     self.assertEquals(date(2009, 11, 1),
                       self.medicine.initial_dispense_date())
 def test_no_clash_when_no_overlap(self):
     self.codeine.add_prescription(
         Prescription(days_ago(30), days_supply=30))
     self.prozac.add_prescription(Prescription(days_ago(90),
                                               days_supply=30))
     self.assertEquals(
         0, len(self.patient.clash([self.codeine, self.prozac], 90)))
Exemple #4
0
 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 test_two_medicines_taken_in_a_partially_overlapping_period(self):
     self.codeine.add_prescription(
         Prescription(days_ago(30), days_supply=30))
     self.prozac.add_prescription(Prescription(days_ago(40),
                                               days_supply=30))
     self.assertEquals(20, len(self.patient.clash(["Codeine", "Prozac"],
                                                  90)))
 def test_two_medicines_taken_overlapping_start_of_period(self):
     self.codeine.add_prescription(
         Prescription(days_ago(91), days_supply=30))
     self.prozac.add_prescription(
         Prescription(days_ago(119), days_supply=30))
     self.assertEquals(set([days_ago(90)]),
                       self.patient.clash(["Codeine", "Prozac"], 90))
 def test_dates_taken_in_past_x_days(self):
     prescription = Prescription( \
         dispense_date=(date.today() - timedelta(days=2)),
         days_supply=4)
     self.assertEquals(set([date.today() - timedelta(days=2),
                            date.today() - timedelta(days=1)]),
                       prescription.dates_taken_in_past_x_days(2))
 def test_days_supply(self):
     prescription = Prescription(dispense_date=date.today(), days_supply=3)
     self.assertEquals([
         date.today(),
         date.today() + timedelta(days=1),
         date.today() + timedelta(days=2)
     ], prescription.days_taken())
 def test_number_of_days_prescribed(self):
     when(self.medicine)._possession_effective_range(90).thenReturn(
         [date(2009, 10, 3) + timedelta(days=i) for i in range(75)])
     self.medicine.add_prescription(
         Prescription(dispense_date=date(2009, 10, 3), days_supply=30))
     self.medicine.add_prescription(
         Prescription(dispense_date=date(2009, 11, 17), days_supply=30))
     self.assertEquals(60, self.medicine.number_of_days_prescribed(90))
 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_dates_taken_when_dates_overlap(self):
     prescriptions = [Prescription(dispense_date=date(2009, 12, 1),
                                   days_supply = 2),
                      Prescription(dispense_date=date(2009, 12, 2),
                                   days_supply = 2))
     self.assertEquals([date(2009, 12, 1),
                        date(2009, 12, 2),
                        date(2009, 12, 3)],
                       self.medicine.dates_taken_in_past_x_days(5))
 def test_dates_prescribed_when_dates_overlap(self):
     self.medicine.add_prescription(
         Prescription(dispense_date=date(2009, 12, 1), days_supply=2))
     self.medicine.add_prescription(
         Prescription(dispense_date=date(2009, 12, 2), days_supply=2))
     self.assertEquals(
         [date(2009, 12, 1),
          date(2009, 12, 2),
          date(2009, 12, 3)], self.medicine.dates_prescribed(5))
Exemple #13
0
 def test_clash_with_two_prescriptions_for_same_medication(self):
     patient = Patient(prescriptions=[
         Prescription("Codeine", dispense_date=days_ago(2), days_supply=2),
         Prescription("Codeine", dispense_date=days_ago(3), days_supply=2)
     ])
     assert patient.clash(["Codeine"]) == {
         days_ago(days=3),
         days_ago(days=2),
         days_ago(days=1)
     }
Exemple #14
0
 def test_days_taking(self):
     patient = Patient(prescriptions=[
         Prescription("Codeine", dispense_date=days_ago(2), days_supply=2),
         Prescription("Codeine", dispense_date=days_ago(3), days_supply=2)
     ])
     assert patient.days_taking("Codeine") == {
         days_ago(days=3),
         days_ago(days=2),
         days_ago(days=1)
     }
 def test_clash_overlapping_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)
     ])
     self.assertSetEqual(
         {days_ago(days=2), days_ago(days=1)},
         patient.clash(["Codeine", "Prozac"]))
 def test_days_taking(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.days_taking('Codeine'))
 def test_clash_with_two_different_prescriptions(self):
     patient = Patient(prescriptions=[
         Prescription(
             "Codeine", dispense_date=days_ago(days=2), days_supply=2),
         Prescription(
             "Prozac", dispense_date=days_ago(days=2), days_supply=2)
     ])
     assert patient.clash(["Codeine", "Prozac"
                           ]) == {days_ago(days=2),
                                  days_ago(days=1)}
 def test_prescriptions_in_range(self):
     when(self.medicine).possession_effective_end_date().thenReturn(
         date(2009, 12, 15))
     p1 = Prescription(dispense_date=date(2009, 8, 1), days_supply=30)
     p2 = Prescription(dispense_date=date(2009, 11, 1), days_supply=30)
     p3 = Prescription(dispense_date=date(2009, 12, 1), days_supply=30)
     self.medicine.add_prescription(p1)
     self.medicine.add_prescription(p2)
     self.medicine.add_prescription(p3)
     self.assertEquals([p2, p3], self.medicine.prescriptions_in_range(90))
Exemple #19
0
 def test_clash_when_medecines_in_history_any_order(self):
     prescA = Prescription(date(2020, 7, 1), 20)
     prescB = Prescription(date(2020, 7, 10), 4)
     prescC = Prescription(date(2020, 7, 10), 10)
     patient = self.prepare_data(prescA, prescB, prescC)
     self.assertEqual(patient.clash(["B", "A"], 20), [
         date(2020, 7, 13),
         date(2020, 7, 12),
         date(2020, 7, 11),
         date(2020, 7, 10)
     ])
Exemple #20
0
 def test_clash_AB_outofrange_C(self):
     prescA = Prescription(date(2020, 7, 15), 5)
     prescB = Prescription(date(2020, 7, 15), 5)
     prescC = Prescription(date(2020, 7, 10), 5)
     patient = self.prepare_data(prescA, prescB, prescC)
     self.assertEqual(patient.clash(["A", "B"], 6), [
         date(2020, 7, 19),
         date(2020, 7, 18),
         date(2020, 7, 17),
         date(2020, 7, 16),
         date(2020, 7, 15)
     ])
     self.assertEqual(patient.clash(["A", "B", "C"], 6), [])
 def test_clash_when_one_medicine_taken_on_some_of_the_days(self):
     self.codeine.add_prescription(
         Prescription(days_ago(30), days_supply=30))
     self.codeine.add_prescription(
         Prescription(days_ago(60), days_supply=30))
     self.prozac.add_prescription(Prescription(days_ago(30),
                                               days_supply=30))
     self.prozac.add_prescription(Prescription(days_ago(60),
                                               days_supply=30))
     self.prozac.add_prescription(Prescription(days_ago(90),
                                               days_supply=30))
     self.assertEquals(60, len(self.patient.clash(["Codeine", "Prozac"],
                                                  90)))
 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"]))
 def test_dates_prescribed_in_effective_range(self):
     self.medicine.add_prescription(
         Prescription(dispense_date=date.today() - timedelta(days=2),
                      days_supply=4))
     self.assertEquals([
         date.today() - timedelta(days=2),
         date.today() - timedelta(days=1)
     ], self.medicine.dates_prescribed_in_effective_range(2))
def prescriptions():
    st.header('PRESCRIPTIONS')
    option_list = ['', 'Add prescription', 'Update prescription', 'Delete prescription', 'Show prescriptions of a particular patient']
    option = st.sidebar.selectbox('Select function', option_list)
    m = Prescription()
    if (option == option_list[1] or option == option_list[2] or option == option_list[3]) and verify_dr_mls_access_code():
        if option == option_list[1]:
            st.subheader('ADD PRESCRIPTION')
            m.add_prescription()
        elif option == option_list[2]:
            st.subheader('UPDATE PRESCRIPTION')
            m.update_prescription()
        elif option == option_list[3]:
            st.subheader('DELETE PRESCRIPTION')
            m.delete_prescription()
    elif option == option_list[4]:
        st.subheader('PRESCRIPTIONS OF A PARTICULAR PATIENT')
        m.prescriptions_by_patient()
Exemple #25
0
    def test_clash_with_two_patients(self):
        prescA = Prescription(date(2020, 7, 1), 20)
        prescB = Prescription(date(2020, 7, 10), 4)
        prescC = Prescription(date(2020, 7, 10), 10)
        medA = Medicine("A")
        medB = Medicine("B")
        medC = Medicine("C")

        medA.add_prescription(prescA)
        medB.add_prescription(prescB)
        medC.add_prescription(prescC)

        patientA = Patient()
        patientB = Patient()
        patientA.add_medicine(medA)
        patientB.add_medicine(medA)
        patientB.add_medicine(medB)
        patientA.add_medicine(medC)
        patientB.add_medicine(medC)
        self.assertEqual(patientA.clash(["A", "B"], 90), [])
Exemple #26
0
def get_prescriptions():
    """\
    Returns a list of all the prescriptions known in the database

    :return: A list of <Prescription> objects
    """
    c = get_cursor()
    cursor = c.execute('''SELECT * FROM Prescriptions''')

    res = []

    for row in cursor:
        res.append(Prescription.parse_raw(row))

    return res
Exemple #27
0
def get_prescriptions_by_uid(uid):
    """\
    Returns a list of prescriptions for a certain patient

    :param uid: The userID of the patient
    :return: A list of <Prescription> objects for the given uid
    """
    c = get_cursor()
    cursor = c.execute('''SELECT * FROM Prescriptions WHERE uid=?''', (uid, ))

    res = []

    for row in cursor:
        res.append(Prescription.parse_raw(row))

    return res
Exemple #28
0
def client_thread(conn):
    # Loop indefinitively
    while True:
        # This blocks the loop untill something is received
        received = conn.recv(1024)
        json_data = ""

        # Received == None
        if not received:
            print("Closing connection")
            break

        # Something was received, decode it
        if received:
            json_data = received.decode()

        # The decoded message is not empty, analyse it
        if json_data != "":
            # The messages use the JSON format
            data = json.loads(json_data)

            # The command is 'login', authenticate the credentials and send back the result
            if data["command"] == "login":
                tosend = {}
                tosend["command"] = "authlogin"
                tosend["auth"] = authenticate(data["username"], data["password"])
                if (tosend["auth"] == "True"):
                    auth = True
                print("Sending: " + json.dumps(tosend))
                conn.send(json.dumps(tosend).encode())

            # The command is 'getprescriptions', get the prescriptions of the user and compress them to a string
            # in JSON format
            if data["command"] == "getprescriptions" and auth:
                user = database.get_user_by_uid(data["uid"])
                print("Info: " + str(user.id) + ", " + str(user.username) + ", " + str(user.rfid))
                prescriptions = user.get_prescriptions()
                tosend = {}
                tosend["command"] = "getprescriptions"
                tosend["data"] = Prescription.to_json_list(prescriptions)
                print("Sending: " + str(tosend))
                conn.send(json.dumps(tosend).encode())

    # Properly close the connection, shutdown notifies the client that is should stop listening
    conn.shutdown(1)
    conn.close()
Exemple #29
0
    def run(self):
        print("Starting " + self.name)
        global running

        while running:
            received = self.sock.recv(1024)
            json_data = ""

            if not received:
                print("Closing connection")
                break

            if received:
                json_data = received.decode()

            if json_data != "":
                # Messages are send in JSON format
                data = json.loads(json_data)
                print("Received: " + str(json_data))

                if data["command"] == "authlogin":
                    if data["auth"] == "True":
                        # When the server accepts the login request, send a new request to the server in order to retrieve the prescriptions of the patient
                        tosend = {}
                        tosend["command"] = "getprescriptions"
                        print("uid: " + str(uid))
                        tosend["uid"] = uid
                        print("Sending: " + str(json.dumps(tosend)))
                        self.sock.send(json.dumps(tosend).encode())
                    elif data["auth"] == "False":
                        # The authentication failed (because of wrong credentials), exit the program
                        # messagebox.showerror("Error", "Authentication failed")
                        print("Authentication failed")
                        running = False
                        s.shutdown(1)
                if data["command"] == "getprescriptions":
                    # The request to retrieve the prescriptions has been answered, convert them to prescription objects and notify the main thread
                    global prescriptions
                    prescriptions = {}
                    prescriptions = Prescription.from_json_list(data["data"])
                    from_dummy_thread(lambda: {unblock_main()})

        print("Exiting " + self.name)
        from_dummy_thread(lambda: unblock_main())
 def test_clash_when_medicines_taken_continuously(self):
     self.codeine.add_prescription(
         Prescription(days_ago(30), days_supply=30))
     self.codeine.add_prescription(
         Prescription(days_ago(60), days_supply=30))
     self.codeine.add_prescription(
         Prescription(days_ago(90), days_supply=30))
     self.prozac.add_prescription(Prescription(days_ago(30),
                                               days_supply=30))
     self.prozac.add_prescription(Prescription(days_ago(60),
                                               days_supply=30))
     self.prozac.add_prescription(Prescription(days_ago(90),
                                               days_supply=30))
     self.assertEquals(90, len(self.patient.clash(["Codeine", "Prozac"],
                                                  90)))
 def test_days_taken_excludes_future_dates(self):
     prescription = Prescription("Codeine", dispense_date = days_ago(days=2), days_supply=4)
     #assert prescription.days_taken() == [days_ago(1), days_ago(2)]
     assert prescription.days_taken() == [days_ago(2), days_ago(1)]
 def test_days_supply(self):
     prescription = Prescription(dispense_date = date.today(), days_supply = 3)
     self.assertEquals([date.today(), date.today()+timedelta(days=1), date.today()+timedelta(days=2)], prescription.days_taken())
 def test_completion_date(self):
     prescription = Prescription(dispense_date = date.today() - timedelta(days=15), days_supply = 30)
     self.assertEquals(date.today() + timedelta(days=15), prescription.completion_date())