Exemplo n.º 1
0
def get_entries():
    req = request.get_json()
    entryType = req['entryType'] #request.form['entryType']
    userInfo = None
    if 'userInfo' in req:
      userInfo = req['userInfo']
    if entryType == 'patient':
        pm = PatientModel()
        entry_list = pm.get_patient_info_list()
    elif entryType == 'doctor':
        dm = DoctorModel()
        entry_list = dm.get_doctor_info_list()
    elif entryType == 'appointment':
        am = AppointmentModel()    
        if userInfo and userInfo['userType'] == 'Patient':
            entry_list = am.get_appointments_by_patient_id(userInfo['userID'])
        else:
            entry_list = am.get_appointment_info_list()

    elif entryType == 'prescription':
        pm = PrescriptionModel()
        entry_list = pm.get_prescription_info_list()
    else:
        entry_list = [{'error':'invalid entry request'}]

    if not isinstance(entry_list, list):
        entry_list = [entry_list]
    
    if len(entry_list) == 1 and not entry_list[0]:
        entry_list = []

    return jsonify(entry_list)
Exemplo n.º 2
0
 def remove_user(self, id):
     '''
     method to remove user from system
     '''
     connection = Dbconnect.get_connection()
     try:
         with connection.cursor() as cursor:
             # remove user from database
             sql = queries["Remove User"]
             cursor.execute(sql, (id))
         # connection is not autocommit by default. So you must commit to save
         # your changes.
         connection.commit()
         # remove patient pertaining to user
         PatientModel().remove_patient(id)
     finally:
         connection.close()
     return "remove user success"
Exemplo n.º 3
0
def get_entry_by_id():
    id = request.form['id']
    entryType = request.form['entryType']
    if entryType == 'patient':
        pm = PatientModel()
        info = pm.get_patient_info_by_id(id)
    elif entryType == 'doctor':
        dm = DoctorModel()
        info = dm.get_doctor_by_id(id)
        #info = [{'testdata':'placeholder'}]
    elif entryType == 'appointment':
        am = AppointmentModel()
        info = am.get_appointment_by_id(id)
        #info = [{'testdata':'placeholder'}]
    elif entryType == 'prescription':
        pm = PrescriptionModel()
        info = pm.get_prescription_by_id(id)
        #info = [{'testdata':'placeholder'}]
    if not isinstance(info, list):
        info = [info]
    return jsonify(info)
Exemplo n.º 4
0
def save_entry():
    req = request.get_json()
    entryType = req['entryType']
    entry = req['entry']

    if entryType == 'patient':
        pm = PatientModel()
        pm.change_patient_info(entry['name'],
                           entry['weight'],
                           entry['address'],
                           entry['phone'],
                           entry['insurance'],
                           entry['height'],
                           entry['medicalhistory'],
                           entry['patientID'])
    elif entryType == 'doctor':
        dm = DoctorModel()
        print(entry)
        dm.change_doctor_info(entry['name'], 
                           entry['specialty'], 
                           entry['location'],
                           entry['doctorID'])
    elif entryType == 'appointment':
        am = AppointmentModel()
        tosave = 'appointmentID' in entry
        if tosave:
            am.change_appointment(entry['appointmentID'],
                                entry["time"])
        else:
            am.make_appointment(entry['doctorID'], entry['patientID'], entry['time'])
            print('save new appointment')
    elif entryType == 'prescription':
        pm = PrescriptionModel()
        tosave = 'prescriptionID' in entry
        if tosave:
            pm.change_prescription(entry['prescriptionID'], entry['prescription'])
        else:
            pm.add_prescription(entry['doctorID'], entry['patientID'], entry['prescription'])
        print(entry)
    return 'save finished'
Exemplo n.º 5
0
def addEntry():
    entryType = request.form['entryType']
    if entryType == 'patient':
        '''
        1. create usermodel object
        2. add a new user
        3. get just added user
        4. create patientmodel object
        5. add a default patient entry
        return
        '''
        um = UserModel()
        um.add_user(None,random_garbage(),random_garbage(),"patient", 3)
        lastEntry = um.get_last_entry()
        pm = PatientModel()
        pm.add_patient(lastEntry['userID'],"",0,0,"",0,"","","","","1111-11-11")
    elif entryType == "doctor":
        '''
        1. create usermodel object
        2. add a new user
        3. get just added user
        4. create doctormodel object
        5. add a default doctor entry
        return
        '''
        um = UserModel()
        um.add_user(None,random_garbage(),random_garbage(),"doctor", 2)
        lastEntry = um.get_last_entry()
        dm = DoctorModel()
        dm.add_doctor(lastEntry['userID'],"","","")
    elif entryType == 'prescription':
        pm = PrescriptionModel()
        pm.add_prescription(0,0,"")
    elif entryType == 'appointment':
        am = AppointmentModel()
        am.make_appointment(0,0,"1111-11-11 11:11:11")
    return 'entry saved'
Exemplo n.º 6
0
def delete_entry():
    entryType = request.form['entryType']
    ID = request.form['ID']
    if entryType == 'patient':
        print(entryType)
        print(ID)
        pm = PatientModel()
        pm.remove_patient(ID)
    elif entryType == 'doctor':
        print(entryType)
        print(ID)
        dm = DoctorModel()
        dm.remove_doctor(ID)
    elif entryType == 'prescription':
        print(entryType)
        print(ID)
        pm = PrescriptionModel()
        pm.remove_prescription(ID)
    elif entryType == 'appointment':
        print(entryType)
        print(ID)
        am = AppointmentModel()
        am.cancel_appointment(ID)
    return 'entry deleted'
Exemplo n.º 7
0
def get_patients():
    pm = PatientModel()
    patient_list = pm.get_patient_info_list()
    return jsonify(patient_list)
Exemplo n.º 8
0
 def test_add_patient(self):
     pm = PatientModel()
     actual_output = pm.add_patient()
     self.assertEqual(actual_output, "add patient success")