def clean(self, request): self.cleaned_data = {} if 'Add' in request.POST: for fieldname in self.fields: if self.fields[fieldname].required and fieldname not in request.POST: messages.error(request, u'Для добавления нужно дополнить данные') self.patients = Patient.objects.all() return False else: if fieldname in request.POST: self.cleaned_data[fieldname] = request.POST[fieldname] try: bd = datetime.strptime(self.cleaned_data['birthdate'], '%Y-%m-%d').date() except: self.patients = Patient.objects.all() return False user = User.objects.create_user(username=self.cleaned_data['polis_number']) user.set_password(self.cleaned_data['password']) user.groups = Group.objects.filter(id=3) user.save() p = Patient(fio=self.cleaned_data['fio'], birthdate=bd, address=self.cleaned_data['address'], phone_number=int(self.cleaned_data['phone_number']), area=Area.objects.get(number=self.cleaned_data['area']), polis_number=self.cleaned_data['polis_number'], user=user, password=self.cleaned_data['password']) p.save() messages.info(request, u'Пациент добавлен') self.patients = Patient.objects.all() self.patients = Patient.objects.all() return True
def dispense_drug_patient (self, message, first, last, gender, age, code, quantity): age = Patient.age_from_str(age) gender = Patient.SEXE_MALE if gender.upper() == 'M' else Patient.SEXE_FEMALE receiver= Patient(first_name=first, last_name=last, sexe=gender,age=age) receiver.save() sender = StoreProvider.cls().by_mobile(message.peer) item = Item.by_code(code) if item == None or sender == None or receiver == None: message.respond(_(u"Dispense request failed. Either Item ID or Patient datas are wrong.")) return True try: log = transfer_item(sender=sender, receiver=receiver, item=item, quantity=int(quantity)) except ItemNotInStore: message.respond(_(u"Dispense request failed. You do not have %(med)s") % {'med': item}) return True except NotEnoughItemInStock: message.respond(_(u"Dispense request failed. You can't dispense %(q)s %(it)s to %(rec)s because you only have %(stk)s.") % {'q': quantity, 'it': item.name, 'rec': receiver.display_full(), 'stk': StockItem.objects.get(peer=sender, item=item).quantity}) return True message.respond("CONFIRMATION #%(d)s-%(sid)s-%(rid)s-%(lid)s You have dispensed %(quantity)s %(item)s to %(receiver)s. If not correct please reply: CANCEL %(lid)s" % { 'quantity': quantity, 'item': item.name, 'receiver': receiver.display_full(), 'd': log.date.strftime("%d%m%y"), 'sid': sender.id, 'rid': receiver.id, 'lid': log.id }) return True
def add_patient(request): if request.method == 'POST': print request.POST firstname = request.POST.get('firstname') print firstname lastname = request.POST.get('lastname') age = request.POST.get('age') dob = request.POST.get('dob') gender = request.POST.get('gender') phone = request.POST.get('phone') description = request.POST.get('description') response_data = {} patient = Patient(firstname=firstname, lastname=lastname, age=age, dob=dob, gender=gender, phone=phone, description=description) patient.save() response_data['result'] = 'Data stored successfully!' return HttpResponse(json.dumps(response_data), content_type="application/json") else: return HttpResponse(json.dumps( {"nothing to see": "this isn't happening"}), content_type="application/json")
def signup(request): """ Sign Up Page, uses built in Sign-Up """ if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') name = form.cleaned_data.get('name') category = form.cleaned_data.get('category') user = authenticate(username=username, password=raw_password) if category == "doctor": doctor = Doctor(user=user, name=name) doctor.save() if category == "pharmacist": pharmacist = Pharmacist(user=user, name=name) pharmacist.save() if category == "patient": patient = Patient(user=user, name=name) patient.save() login(request, user) return redirect('/pharm/profile') else: form = SignUpForm() return render(request, 'pharmeasyflow/signup.html', {'form': form})
def add_patient(self, ccd_file, pref_email): #Because of a chicken-egg problem, we need to write the CCDA to disk then have bluebutton parse it before we can #pass it to a model with NamedTemporaryFile(delete=False) as xml_file: for chunk in ccd_file.chunks(): xml_file.write(chunk) ccda = parse_ccda(xml_file.name) new_user = User.objects.create_user(pref_email, pref_email, 'password') new_user.first_name = ccda['demographics']['name']['given'][0] new_user.last_name = ccda['demographics']['name']['family'] new_user.save() new_patient = Patient(user=new_user, chart=ccd_file) new_patient.save()
def save_patient(patient_data, user): patient = Patient( id=patient_data['id'], first_name=patient_data['first_name'], last_name=patient_data['last_name'], email=patient_data['email'], birthday=patient_data['date_of_birth'], doctor=user.doctor ) if Patient.objects.filter(pk=patient_data['id']).exists(): patient.save( update_fields=['first_name', 'last_name', 'email', 'birthday'] ) else: patient.save() return patient
def submit(request): from models import id_generator postKeyReturn = check_post_key(request) if postKeyReturn is not True: return postKeyReturn # Because the post is not indexed we have to check the key if len(unicode(request.body)) == 0: return HttpResponseBadRequest() # Check if it really json try: json_object = json.loads(unicode(request.body)) except ValueError as e: print e # TODO: use real logging # The json is not valid return HttpResponseBadRequest() pat = Patient() uid = id_generator() # Check if the uid exists while Patient.objects.filter(uid__iexact=uid).count() == 1: uid = id_generator() pat.uid = uid pat.first_name = json_object.get("first_name") or None pat.last_name = json_object.get("last_name") or None pat.moh_id = json_object.get("moh_id") or None pat.enter_number = json_object.get("enter_number") or None pat.caregiver_number = json_object.get("caregiver_number") or None pat.json = unicode(json_object) # Message is sent through the save method pat.save() return HttpResponse(uid)
def get_patient_for_user(appt, user, access_token): patient = appt['patient'] p = None try: p = Patient.objects.get(drchrono_id=patient) except Patient.DoesNotExist: patient_uri = drchrono_base_url + patients_url + '/' + str(patient) patient_data = requests.get( patient_uri, headers={'Authorization': 'Bearer %s' % access_token} ).json() p = Patient() p.drchrono_id = patient p.first_name = patient_data.get('first_name') p.last_name = patient_data.get('last_name') p.email = patient_data.get('email') p.gender = patient_data.get('gender') p.race = patient_data.get('race') p.photo = patient_data.get('photo') p.drchrono_doctor_id = patient_data.get('doctor') p.user_id = user.id p.save() return p
def save_patient(patient_data, user): """ :param patient_data: :param user: Save patient data to local database to provide quicker access when editing demographics """ patient = Patient( id=patient_data['id'], doctor=user, first_name=patient_data['first_name'], middle_name=patient_data['middle_name'], last_name=patient_data['last_name'], address=patient_data['address'], email=patient_data['email'], home_phone=patient_data['home_phone'], cell_phone=patient_data['cell_phone'], city=patient_data['city'], zip_code=patient_data['zip_code'], state=patient_data['state'], emergency_contact_name=patient_data['emergency_contact_name'], emergency_contact_phone=patient_data['emergency_contact_phone'], emergency_contact_relation=patient_data['emergency_contact_relation'], employer=patient_data['employer'], employer_city=patient_data['employer_city'], employer_state=patient_data['employer_state'], employer_address=patient_data['employer_address'], employer_zip_code=patient_data['employer_zip_code'], primary_care_physician=patient_data['primary_care_physician'], social_security_number=patient_data['social_security_number'], responsible_party_name=patient_data['responsible_party_name'], responsible_party_phone=patient_data['responsible_party_phone'], responsible_party_relation=patient_data['responsible_party_relation'], responsible_party_email=patient_data['responsible_party_email'], ) patient.save()
def handle_uploaded_file(f): file_name = f.name file_size = f.size result = 'Success' first_line = True all_patients = Patient.objects.all() for line in f: # The first line of the file will always be headers if not first_line: # The data will always be separated by tabs split = line.split('\t') if len(split) == 14: patient_id = split[0] for p in all_patients: if p.id == patient_id: p.delete() patient = Patient(id=patient_id, height=get_value(split[1]), egplandt=get_date(split[2]), egpregdt=get_date(split[3]), egstage4dt=get_date(split[4]), egcd4dt=get_date(split[5]), egcd4v=get_value(split[6]), edate=get_date(split[7]), egweight=get_value(split[8]), enroldt=get_date(split[9]), lastdt=get_date(split[10]), returndt=get_date(split[11]), startdt=get_date(split[12]), startgprg=trim(split[13])) #TODO: there will be one more field coming patient.save() else: result = 'At least one line of the file did not have the correct number of entries and was not added' else: first_line = False return result
def patientAdd(request): otherVars = {'pageType': 'logon', 'UserInfo': request.user.first_name} # if request method is post if request.method == 'POST': addPatientForm = AddPatientForm(request.POST) # input validation for add user and user profile form if addPatientForm.is_valid(): # save the user and user profile object into database patientIns = Patient() patientIns.nric = request.POST['nric'] patientIns.full_name = request.POST['full_name'] patientIns.contact_num = request.POST['contact_num'] patientIns.gender = request.POST['gender'] patientIns.dob = request.POST['dob'] patientIns.address = request.POST['address'] patientIns.postalcode = request.POST['postalcode'] patientIns.nok = request.POST['nok'] patientIns.age = date.today().year - int( str(patientIns.dob).split('-')[0]) patientIns.email = request.POST['email'] patientIns.allergy = request.POST['allergy'] patientIns.visit_time = time() patientIns.save() return HttpResponseRedirect(reverse('patientView')) else: addPatientForm = AddPatientForm() # Define header groups hgrps = ( { 'name': 'Patient Information', 'lblwidth': '160' }, { 'name': 'Next-of-Kin Information', 'lblwidth': '160' }, ) # For first header group addPatientForm.fields["nric"].widget.attrs['hgrp'] = '0' addPatientForm.fields["nric"].widget.attrs['wsize'] = '300' addPatientForm.fields["full_name"].widget.attrs['hgrp'] = '0' addPatientForm.fields["full_name"].widget.attrs['wsize'] = '300' addPatientForm.fields["contact_num"].widget.attrs['hgrp'] = '0' addPatientForm.fields["contact_num"].widget.attrs['wsize'] = '300' addPatientForm.fields["gender"].widget.attrs['hgrp'] = '0' addPatientForm.fields["gender"].widget.attrs['wsize'] = '120' # # For first header group addPatientForm.fields["dob"].widget.attrs['hgrp'] = '0' addPatientForm.fields["dob"].widget.attrs['wsize'] = '150' addPatientForm.fields["address"].widget.attrs['hgrp'] = '0' addPatientForm.fields["address"].widget.attrs['wsize'] = '300' addPatientForm.fields["postalcode"].widget.attrs['hgrp'] = '0' addPatientForm.fields["postalcode"].widget.attrs['wsize'] = '300' addPatientForm.fields["email"].widget.attrs['hgrp'] = '0' addPatientForm.fields["email"].widget.attrs['wsize'] = '300' addPatientForm.fields["allergy"].widget.attrs['hgrp'] = '0' addPatientForm.fields["allergy"].widget.attrs['wsize'] = '300' addPatientForm.fields["nok"].widget.attrs['hgrp'] = '1' addPatientForm.fields["nok"].widget.attrs['wsize'] = '300' return render(request, 'main/patientchng.html', { 'otherVars': otherVars, 'addPatientForm': addPatientForm, 'hgrps': hgrps })
def add(req): patient = Patient() patient.setReq(req.POST) patient.save()