def add_patient(): """This function creates a new patient. This function connects to the Mongo database, and posts data to the database. It uses a try statement to validate the data being parsed into the function. If the data is not valid then a Validation Error is returned. The function also sets up a model for the data being parsed in and saves it to the Patient class. It returns a message to confirm the addition of the new patient to the database. :return: message :rtype: str """ connect("mongodb://*****:*****@ds157503.mlab.com:57503/bme590") r = request.get_json() # parses the POST request body as JSON try: validate_patient(r) except ValidationError as inst: return jsonify({"message": inst.exception}), 500 p = Patient( patient_id=r["patient_id"], attending_email=r["attending_email"], user_age=r["user_age"]) p.save() result = { "message": "Added patient {0} successfully to the patient list".format( request.json["patient_id"])} return jsonify(result)
def addpaciente(ops): form_data = { 'name': '', 'lastname': '', 'dni': '', 'email': '', 'admin': '' } try: if not User.get(userid=ops).rol == 'admin': return redirect('/wrongops') except AttributeError: return 'Ingreso no valido, vuelva a la pagina anterior' if request.method == 'POST': if request.forms.get('medico') == "medico": return redirect('/addmedic/{}'.format(ops)) elif request.forms.get('operador') == "operador": return redirect('/addoperator/{}'.format(ops)) elif request.forms.get('paciente') == "paciente": return redirect('/addpaciente/{}'.format(ops)) elif request.forms.get('volver') == "volver": return redirect('/operator/{}'.format(ops)) if request.method == 'POST': form_data['name'] = request.forms.get('name') form_data['lastname'] = request.forms.get('lastname') form_data['dni'] = request.forms.get('dni') form_data['email'] = request.forms.get('email') form_data['patient'] = 1 if not form_data['name']: return "Complete todos los campos!, <a href='/addpaciente/{}'>volver atras</a>".format(ops) if not form_data['lastname']: return "Complete todos los campos!, <a href='/addpaciente/{}'>volver atras</a>".format(ops) if not form_data['dni']: return "Complete todos los campos!, <a href='/addpaciente/{}'>volver atras</a>".format(ops) if not form_data['email']: return "Complete todos los campos!, <a href='/addpaciente/{}'>volver atras</a>".format(ops) if Patient.exists(dni=int(request.forms.get('dni'))): return "El DNI ya esta registrado, registre otro!, <a href='/addpaciente/{}'>volver atras</a>".format(ops) elif Patient.exists(email=str(request.forms.get('email'))): return "El Email ya esta registrado, use otro!, <a href='/addpaciente/{}'>volver atras</a>".format(ops) create = Usermgmt() if create.adduser(form_data): return "Paciente creado, <a href='/addpaciente/{}'>volver atras</a>".format(ops)
def patient_add(): for i in range(2): Patient(dni=config['loader']['patients']['data']['dni'][i], name=config['loader']['patients']['data']['name'][i], lastname=config['loader']['patients']['data']['lastname'][i], secureid=config['loader']['patients']['data']['secureid'][i], email=config['loader']['patients']['data']['email'][i])
def add_patient_answers(answers): """ Inserts new answers from a patient. :param answers: patient answers :param session: current session :return: patient with anonymous name """ session = init() new_answers = [] for key in answers.keys(): new_answers.append(answers[key]) new_entity = Entity(name=random_string(get_all_entities()), type="patient") new_patient = Patient(date_of_birth="11.11.11", entity=new_entity) new_address = Address(post_code="1337", entity=new_entity) session.add(new_address) session.add(new_patient) session.add(new_entity) for answer in answers: q = session.query(Question).filter(Question.id == answer).first() if q is not None: try: new_score = Score(entity=new_entity, question=q, score=answers[answer]) session.add(new_score) session.commit() except: session.rollback() print("Error: Could not save patient scores to database") return new_entity.name
def show_morpheus(sender): #wh = ui.get_screen_size() #f=(0,0,wh[0],wh[1]) f=(0,0,350,650) tabs = ['All', 'Outpt', 'Inpt', 'Inactive'] extra_tabs= ui.SegmentedControl() extra_tabs.segments = ['To See', 'Seen'] extra_tabs.name = 'todaytab' items_toAdd = [{'title':'Patient', 'object':Patient()}, {'title':'Act', 'object':Act()}] Morpheus(Patient, items_toAdd, frame = f, tabs_contents = tabs, extra_data = extra_tabs)
def register() -> int: pat_stat = input( "Press 'n' for registering new patient\nPress 'r' for re-visit\n" ).lower() if pat_stat == 'n': add_paient( Patient(input('Name: '), input('Place: '), input('Phone: '), int(input('Age: ')), 1)) print('Patient registered') elif pat_stat == 'r': print(reg_no(input('Enter the registration number: '))) return 1 if input("Do you want to continue? ") else 0
def main_userdel_paciente_index(ops): if User.get(userid=ops).rol == 'admin': print("este es un usuario admin") else: return redirect('/wrongops') try: if request.forms.get('volver') == "volver": return redirect('/operator/{}'.format(ops)) elif request.forms.get('operador') == "operador": return redirect('/userdel_operador/{}'.format(ops)) elif request.forms.get('paciente') == "paciente": return redirect('/userdel_paciente/{}'.format(ops)) elif request.forms.get('medico') == "medico": return redirect('/userdel/{}'.format(ops)) if request.method == 'POST': dni = request.forms.get('dni') if Patient.exists(dni=dni): obj = Patient.get(dni=dni) nombre = obj.name apellido = obj.lastname obj.delete() query = "a for a in Agenda if a.dni == '{}'".format(int(dni)) cmdquery = select(query)[:] print(cmdquery) for disable in cmdquery: print("deshabilitando todos los turnos del usuario") disable.state = False commit() return "Paciente {} {} borrado del sistema, <a href='/userdel/{}'>volver atras</a>".format(nombre,apellido,ops) else: return "El DNI no existe!, <a href='/userdel_operador/{}'>volver atras</a>".format(ops) except ValueError: return "Ingrese un DNI valido, <a href='/userdel_operador/{}'>volver atras</a>".format(ops)
def adduser(self,data): try: if data['medico']: print("output 1") nonempty_spec_list = [] nonempty_spec_list_id = [] magenda = agenda_cargador(data) print("salida:") print(data) #Genera una nueva lista de especialidades si esta no #existiere for spec in data['specialization'].split(","): if not Speciality.get(name=spec): Speciality(name=spec) commit() print("output 2") #Suma al nuevo medico a la lista de especialidades for spec in data['specialization'].split(","): query = "m for m in Medic if m.speciality.name == '{}' and m.medicid == '{}'".format(spec,data['medicid']) cmdquery = select(query)[:] if cmdquery: nonempty_spec_list.append(False) else: nonempty_spec_list.append(spec) print("output 3") for i in nonempty_spec_list: nonempty_spec_list_id.append(Speciality.get(name=i)) print("output 4") for i in nonempty_spec_list_id: if i: Medic(name=data['name'], lastname=data['lastname'], medicid=data['medicid'], patient=None, speciality=i) commit() print("output 5") #Genera una agenda libre para el medico query = "m for m in Medic if m.speciality.name == '{}' and m.medicid == '{}'".format(spec,data['medicid']) cmdquery = select(query)[:] dbmedicid = cmdquery[0] months = ["Enero-1","Febrero-2","Marzo-3","Abril-4","Mayo-5","Junio-6", "Julio-7","Agosto-8", "Septiembre-9","Octubre-10","Noviembre-11","Diciembre-12"] dias = ["lunes","martes","miercoles","jueves","viernes","sabado","domingo"] hours = ["10","11","12"] monthday_array = [] for k, v in magenda.items(): if v['lunes']['dias'] or v['martes']['dias'] or v['miercoles']['dias'] \ or v['jueves']['dias'] or v['viernes']['dias'] or v['sabado']['dias'] \ or v['domingo']['dias']: for d in dias: for tdias in v[d]['dias']: for hr in v[d]['horario'][0]: monthday = k + "/" + d + "-" + str(tdias) + "/" + str(hr) monthday_array.append(monthday) print("output 6") for md in monthday_array: Agenda(date=md, state=0, hour=md.split("/")[2], medico=dbmedicid.id) commit() newuser = User(name=data['name'], lastname=data['lastname'], userid=data['userid'], password=data['password'], medicid=data['medicid'],rol="medic") commit() print("comiteo") return True except: pass try: if data['admin']: newuser = User(name=data['name'], lastname=data['lastname'], userid=data['userid'], password=data['password'], rol="admin") commit() print("comiteo") return True except: pass try: if data['patient']: if not Patient.get(dni=data['dni']): newuser = Patient(name=data['name'], lastname=data['lastname'], dni=data['dni'], email=data['email']) commit() print("comiteo") return True except: pass
def medicassign(self,data): hour = data['ingreso3'].split(" ")[1].split(":")[1] date = data['ingreso2'] + "/" + data['ingreso3'].split(" ")[0] + "/" + hour patientdni = data['patient'].split("-")[1].split(" ")[1] idmedic = data['ingreso1'] comment = data['comments'] medictype = False inc = 0 print(data) query = "m for m in Medic if m.speciality.name == '{}'".format(data['ingreso0']) medico = select(query)[:] medico_posta = medico[0] query = "a for a in Agenda if a.date == '{}' and a.medico.medicid == '{}' and a.hour == '{}'".format(date, idmedic, hour) cmdquery = select(query)[:] try: obj = cmdquery[0] except IndexError: return "error" print("salida 2") #Me trae el medico segun especialidad if obj.medico.speciality.name == data['ingreso0']: print("ok") else: query = "m for m in Medic if m.speciality.name == '{}'".format(data['ingreso0']) medico = select(query)[:] medico_posta = medico[0] # Valida si el estado del medico se encuentra disponible. if obj.state == False: p = Patient.get(dni=patientdni).id pemail = Patient.get(dni=patientdni).email date_splited = date.split("/")[0] + "/" + date.split("/")[1] obj.date = date obj.hour = hour obj.patient = p obj.comments = comment obj.state = 1 obj.medico = medico_posta.id #Obtengo nombre del medico nombre_medico = obj.medico.name #Genera un turno. a = Turno[1] a.turno = a.turno + 1 obj.turno = a.turno obj.dni = int(patientdni) commit() #Sent email EnviarEmail = Email() EnviarEmail.send(pemail,nombre_medico,date_splited,hour,a.turno) return "ok" else: print("error")