def fill_form(): form = UpdatePatient() ssnid = request.args['messages'] room_amount = 0 pat = Registration.objects(patient_ssnid=ssnid).first() form.patient_ssnid.data = ssnid if form.submit.data: if request.method == "POST": name = request.form["patientname"] age = request.form["age"] address = request.form["address"] #state = request.form["state"] #city = request.form["city"] state = str(dict(form.state.choices).get(form.state.data)) city = str(dict(form.city.choices).get(form.city.data)) bed_type = str( dict(form.type_of_bed.choices).get(form.type_of_bed.data)) if bed_type == "General Ward": room_amount = 2000 elif bed_type == "Sharing Ward": room_amount = 4000 else: room_amount = 8000 Registration.objects(patient_ssnid=ssnid).update( patient_name=name, bed_type=bed_type, age=age, address=address, state=state, city=city, room_amount=room_amount) flash("Patient Update initiated successfully", "success") return render_template("updatepatient.html", form=form, pat=pat)
def patientRegistration(): form =CreatePatient() patient_ssnid =form.patient_ssnid.data room_amount = 0 if form.validate_on_submit(): if Registration.objects(patient_ssnid=patient_ssnid): flash("A patient is already registered with this ID","danger") else: name = form.name.data age = form.age.data bedtype=str(dict(form.type_of_bed.choices).get(form.type_of_bed.data)) if bedtype=="General Ward" : room_amount=2000 elif bedtype=="Sharing Ward": room_amount = 4000 else: room_amount= 8000 address=form.address.data doj=str(form.date_of_admission.data) state= str(dict(form.state.choices).get(form.state.data)) city= str(dict(form.city.choices).get(form.city.data)) if len(patient_ssnid)==9: patient= Registration(patient_ssnid=patient_ssnid,patient_name=name, age=age,bed_type=bedtype,address=address,state=state,city=city,doj=doj , room_amount = room_amount) patient.save() flash("Patient Registration Initiated Successfully","success") else: flash("Patient SSNID should be exactly 9 digits","danger") return render_template("patientRegistration.html",form=form)
def event_submit(event_id): """Saves registration information about user for an event""" # Gets the specific event information event = Event.query.get(event_id) # Verifies the user user_id = session.get("user_id") if not user_id: flash("Please log in to register for event", "warning") return redirect("/") # user = User.query.get(user_id) # Gets Form Variables questions = event.questions values = request.form.getlist("question") # Gets Id for each question question_ids = [q.id for q in questions] # Adds a new registration to the session new_registration = Registration() new_registration.user_id = user_id new_registration.event_id = event_id new_registration.timestamp = datetime.now() db.session.add(new_registration) # Adds the answers for each question to the session for i in range(len(questions)): new_answer = Answer() new_answer.value = values[i] new_answer.question_id = question_ids[i] new_answer.registration = new_registration db.session.add(new_answer) # Commits both the registration and all the answers to the database db.session.commit() # Charge the attendee token = request.form.get('stripeToken', None) if token is not None: charged_id = charge_card(token, event.price) # TODO: store the charge_id in the event if not charged_id: raise Exception("Payment error") flash("Successfully Registered for event", "success") msg = Message("You're Registered!!!!", sender="*****@*****.**", recipients=["*****@*****.**"]) msg.body = "This is the email body" mail.send(msg) # return redirect("/user_profile/%s" % user_id) return render_template("success.html", event=event, user_id=user_id)
def fill_form1(): form = UpdatePatient() ssnid = request.args['msg'] pat = Registration.objects(patient_ssnid=ssnid).first() form.patient_ssnid.data = ssnid bed_type = str(dict(form.type_of_bed.choices).get(form.type_of_bed.data)) if form.delete.data: Registration.objects(patient_ssnid=ssnid).delete() GiveMedicine.objects(patient_ssnid=ssnid).delete() IssueDiagnostics.objects(patient_ssnid=ssnid).delete() flash("Patient Deletion Initiated Succefully", "success") return render_template("deletepatient.html", form=form, pat=pat)
def search_patient(): form = UpdatePatient() if not session.get('login_id'): return redirect(url_for('admin_login')) patient_ssnid = form.patient_ssnid.data pat = Registration.objects(patient_ssnid=patient_ssnid).first() if form.get.data: if Registration.objects(patient_ssnid=patient_ssnid): flash("Patient Found", "success") return fill_form2(patient_ssnid) else: flash("This ID is not registered", "danger") return render_template("searchpatient.html", form=form, pat=pat)
def fill_form2(data): form= UpdatePatient() pat=Registration.objects(patient_ssnid=data).first() if form.submit.data: if request.method == "POST": name = request.form["patientname"] age = request.form["age"] address = request.form["address"] state = request.form["state"] city = request.form["city"] Registration.objects(patient_ssnid=data).update(patient_name=name,age=age,address=address,state=state,city=city) flash("Patient update initiated successfully","success") return render_template("searchpatient.html",form=form,pat = pat)
def delete_patient(): form = UpdatePatient() if not session.get('login_id'): return redirect(url_for('admin_login')) patient_ssnid = form.patient_ssnid.data pat = Registration.objects(patient_ssnid=patient_ssnid).first() bed_type = str(dict(form.type_of_bed.choices).get(form.type_of_bed.data)) if form.get.data: if Registration.objects(patient_ssnid=patient_ssnid): flash("Patient Found", "success") return redirect(url_for('fill_form1', msg=patient_ssnid)) else: flash("This ID is not registered", "danger") return render_template("deletepatient.html", form=form, pat=pat)
def updateOrInsertRegistration( self, accountName, registrationId ): itemquery = db.GqlQuery("SELECT * FROM Registration WHERE accountName=:1", accountName ) items = itemquery.fetch(1) if len(items)>0: registration=items[0] if registrationId=="": # unregistration registration.delete() else: registration.registrationId=registrationId registration.put() else: registration=Registration() registration.accountName=accountName registration.registrationId=registrationId registration.put()
def link_card(path_to_card: str, club_name: str): data = request_ocr(path_to_card) result = get_card_data(data) user = User.query.filter_by(student_id=result["user"]["student_id"]).first() club = Club.query.filter_by(abbreviation=club_name).first() if not user: user = User(**result["user"]) db.session.add(user) if not club: club = Club(name=club_name) db.session.add(club) db.session.commit() registration = Registration.query.filter_by(user_id=user.id, club_id=club.id).first() if registration: raise BadRequest("Registration Already Exists") registration = Registration(user_id=user.id, club_id=club.id, evidence=path_to_card, expiry=result["card"]["expiry"]) db.session.add(registration) db.session.commit() return registration
def issue_medicine(): amount = 0 form = IssueMedicine123() if not session.get('login_id'): return redirect(url_for('admin_login')) form.med_name1.choices = [(medicine.med_id, medicine.med_name) for medicine in Medicine.objects().all()] ssnid = form.patient_ssnid.data quant = form.quant.data if Registration.objects(patient_ssnid=ssnid): name = Medicine.objects(med_id=form.med_name1.data).first().med_name #if Medicine.objects(med_name = name): if Medicine.objects(med_name=name).first().quant_available >= quant: amount = Medicine.objects(med_name=name).first().rate * quant price = Medicine.objects(med_name=name).first().rate ismed = GiveMedicine(patient_ssnid=ssnid, med_name=name, quantity=quant, amount=amount, rate=price) ismed.save() Medicine.objects(med_name=name).update( quant_available=Medicine.objects( med_name=name).first().quant_available - quant) flash("Medicine is successfully Issued", "success") else: flash( "This much quantity of Medicine is not available in the store", "danger") return render_template("issuemedicine.html", form=form, amount=amount)
def process(self, data): registration = Registration.from_json(data) output = self.disposition(registration) if registration.uuid: self.output_for_uuid[registration.uuid] = output if registration.parent: # In the previous step, children were processed # immediately after their parents. That means they're # processed after their parents here. parent_output = self.output_for_uuid[registration.parent['uuid']] # In general, children are totally independent # registrations. However, if the 'parent' registration # (the one for which the most data is available) was # deemed to be out of range, there's a good chance the # 'children' are also out of range. if parent_output and output == self.in_range and parent_output != self.in_range: registration.disposition = "Classified with parent." registration.warnings.append( "This registration seems to be in range, but it was associated with a registration which was a foreign publication or not in range. To be safe, this registration will be put in the same category as its 'parent'; it should be checked manually." ) output = parent_output json.dump(registration.jsonable(require_disposition=True), output) output.write("\n")
def event_submit(event_id): event = Event.query.get(event_id) user_id = session.get("user_id") if not user_id: flash("Please log in to register for event") return redirect("/") questions = event.questions values = request.form.getlist("question") question_ids = [q.id for q in questions] new_registration = Registration() new_registration.user_id = user_id new_registration.event_id= event_id new_registration.timestamp= datetime.now() db.session.add(new_registration) for i in range (len(questions)): new_answer = Answer() new_answer.value = values[i] new_answer.question_id = question_ids[i] new_answer.registration = new_registration db.session.add(new_answer) db.session.commit() flash("Successfully Registered for event") # Charge if necessary token = request.form.get('stripeToken', None) # import pdb; pdb.set_trace() if token is not None: charged_id = charge_card(token, event.price) # TODO: store the charge_id in the event if not charged_id: raise Exception("Payment error") return redirect("/user_profile/%s" % user_id)
def pharm(): form = Pharmacy() if not session.get('login_id'): return redirect(url_for('admin_login')) acc = 0 ssnid = form.patient_ssnid.data print(ssnid) details = Registration.objects(patient_ssnid=ssnid) meds_used = GiveMedicine.objects(patient_ssnid=ssnid) doj = "" # amount=0 if form.get.data: if Registration.objects(patient_ssnid=ssnid).first(): details = Registration.objects(patient_ssnid=ssnid) meds_used = GiveMedicine.objects(patient_ssnid=ssnid) year_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[0:4] month_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[5:7] day_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[8:10] doj = day_doj + "-" + month_doj + "-" + year_doj flash("Patient Found", "success") else: flash("This ID is not registered", "danger") elif request.method == "POST": ssnid = form.patient_ssnid.data if Registration.objects(patient_ssnid=ssnid): if 'update' in request.form: print("in loop") #print(ssnid) med = request.form[str(0)] quan = request.form[str(1)] rate = request.form[str(2)] if med == "" or quan == "" or rate == "": flash("Enter the values", "danger") else: amount = int(quan) * int(rate) ismed = GiveMedicine(patient_ssnid=ssnid, med_name=med, quantity=quan, amount=amount, rate=rate) ismed.save() flash("The Medicine is added to the Patient", "success") return render_template("pharmacy.html", form=form, doj=doj, det=details, meds=meds_used, acc=1)
def process(self, registration): renewals = self.comparator.renewal_for(registration) registration.renewals = renewals json.dump(registration.jsonable(require_disposition=True), self.output) self.output.write("\n") if registration.is_foreign: # This looks like a foreign registration. We'll filter it out # in the next step, but we need to record its cross-references # now, so we can filter _those_ out in the next step. for xref in registration.parse_xrefs(): out = self.cross_references json.dump(xref.jsonable(), out) out.write("\n") # Handle children as totally independent registrations. Note # that in the next step we may disquality children because the # parent registration was disqualified based on more complete # information. for child in registration.children: child = Registration(**child) child.parent = registration self.process(child)
def renewal_for(self, registration): """Find a renewal for this registration. If there's more than one, find the best one. """ renewals = [] renewal = None for regnum in registration.regnums: renum = regnum.replace("-", "") if regnum in self.renewals: renewals.extend(self.renewals[regnum]) if renewals: renewals, disposition = self.best_renewal(registration, renewals) registration.disposition = disposition else: registration.disposition = "Not renewed." renewals = [] if not renewals: # We'll count it as a decent match if we can find a # renewal based solely on title/author. # # n.b. right now there seem to be no such matches. key = registration.renewal_key renewals_for_key = self.renewals_by_key[key] if renewals_for_key: renewals, disposition = self.best_renewal( registration, renewals_for_key) registration.disposition = "Possibly renewed, based solely on title/author match." if not renewals: # We'll count it as a tentative match if there has _ever_ been a renewal # for a book with a nearly-identical title. title = Registration._normalize_text( registration.title) or registration.title renewals_for_title = self.renewals_by_title[title] if renewals_for_title: renewals, disposition = self.best_renewal( registration, renewals_for_title) registration.disposition = "Possibly renewed, based solely on title match." for renewal in renewals: # These renewals have been matched; they should not be # output in the list of unmatched renewals. self.used_renewals.add(renewal) return renewals
def __init__(self): self.not_books_proper = open("output/3-registrations-not-books-proper.ndjson", "w") self.foreign = open("output/3-registrations-foreign.ndjson", "w") self.too_old = open("output/3-registrations-too-early.ndjson", "w") self.too_new = open("output/3-registrations-too-late.ndjson", "w") self.in_range = open("output/3-registrations-in-range.ndjson", "w") self.errors = open("output/3-registrations-error.ndjson", "w") self.foreign_xrefs = defaultdict(list) self.output_for_uuid = dict() for i in open( "output/2-cross-references-in-foreign-registrations.ndjson" ): data = json.loads(i) reg = Registration(**data) for regnum in reg.regnums: self.foreign_xrefs[regnum].append(reg)
def diagnostics(): form = Diagnostics() if not session.get('login_id'): return redirect(url_for('admin_login')) ssnid = form.patient_ssnid.data details = Registration.objects(patient_ssnid=ssnid) test = IssueDiagnostics.objects(patient_ssnid=ssnid) doj = "" #if form.validate_on_submit(): if form.get.data: if Registration.objects(patient_ssnid=ssnid): details = Registration.objects(patient_ssnid=ssnid) test = IssueDiagnostics.objects(patient_ssnid=ssnid) year_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[0:4] month_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[5:7] day_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[8:10] doj = day_doj + "-" + month_doj + "-" + year_doj flash("Patient Found", "success") else: flash("This ID is not registered", "danger") elif request.method == "POST": print("post") if Registration.objects(patient_ssnid=ssnid): print("patient") if 'update' in request.form: print("update") name = request.form[str(0)] amount = request.form[str(1)] up = IssueDiagnostics(patient_ssnid=ssnid, test_name=name, amount=amount) up.save() flash("Diagnostics Test added Successfully to the Patient", "success") return render_template("diagnostics.html", form=form, doj=doj, det=details, tests=test)
def __init__(self, renewals_input_path): self.renewals = defaultdict(list) self.renewals_by_title = defaultdict(list) self.renewals_by_key = defaultdict(list) for i in open(renewals_input_path): renewal = Renewal(**json.loads(i)) regnum = renewal.regnum if not regnum: regnum = [] if not isinstance(regnum, list): regnum = [regnum] for r in regnum: r = (r or "").replace("-", "") self.renewals[r].append(renewal) title = Registration._normalize_text( renewal.title) or renewal.title self.renewals_by_title[title].append(renewal) self.renewals_by_key[renewal.renewal_key].append(renewal) self.used_renewals = set()
def issue_diagnostics(): amount = 0 form = Issue_Diagnostics() if not session.get('login_id'): return redirect(url_for('admin_login')) form.test_name1.choices=[(i.diag_id,i.test_name) for i in DiagnosticsMasterFile.objects().all()] ssnid = form.patient_ssnid.data #print(form.test_name1.choices) if Registration.objects(patient_ssnid= ssnid).first(): test_name= DiagnosticsMasterFile.objects(diag_id=form.test_name1.data).first().test_name if DiagnosticsMasterFile.objects(test_name = test_name): amount = DiagnosticsMasterFile.objects(test_name = test_name).first().rate give_dia = IssueDiagnostics(patient_ssnid = ssnid,test_name = test_name , amount = amount) give_dia.save() flash("The Diagnostics is issued to Patient","success") return render_template("issuedia.html",form = form, amount = amount)
def updateOrInsertRegistration(self, accountName, registrationId): itemquery = db.GqlQuery( "SELECT * FROM Registration WHERE accountName=:1", accountName) items = itemquery.fetch(1) if len(items) > 0: registration = items[0] if registrationId == "": # unregistration registration.delete() else: registration.registrationId = registrationId registration.put() else: registration = Registration() registration.accountName = accountName registration.registrationId = registrationId registration.put()
def billing(): form = Bill() if not session.get('login_id'): return redirect(url_for('admin_login')) test_sum = 0 med_sum = 0 doj = "" dod = "" calc = "" room_calc = 0 ssnid = form.patient_ssnid.data #dod = form.dod.data details = Registration.objects(patient_ssnid=ssnid) test = IssueDiagnostics.objects(patient_ssnid=ssnid) for i in test: test_sum += i.amount meds_used = GiveMedicine.objects(patient_ssnid=ssnid) for k in meds_used: med_sum += k.amount #if form.validate_on_submit(): if form.get.data: if Registration.objects(patient_ssnid=ssnid).first(): n = Registration.objects(patient_ssnid=ssnid).first() n = n.status if n == "Discharged": flash("The Patient is already Discharged", "danger") dt = datetime.now() year = str(dt.year) month = str(dt.strftime("%m")) day = str(dt.day) year_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[0:4] month_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[5:7] day_doj = str( Registration.objects( patient_ssnid=ssnid).first().doj)[8:10] dod = day + "-" + month + "-" + year doj = day_doj + "-" + month_doj + "-" + year_doj details = Registration.objects(patient_ssnid=ssnid) meds_used = GiveMedicine.objects(patient_ssnid=ssnid) test = IssueDiagnostics.objects(patient_ssnid=ssnid) enter = datetime(int(year), int(month), int(day)) leave = datetime(int(year_doj), int(month_doj), int(day_doj)) calc = str(abs(leave - enter))[0:2] room_calc = int(calc) * Registration.objects( patient_ssnid=ssnid).first().room_amount return render_template('billing.html', form=form, det=details, med=meds_used, n=n, test=test, test_sum=test_sum, med_sum=med_sum, tot=test_sum + med_sum + int(room_calc), dod=dod, doj=doj, calc=calc, room_calc=room_calc) else: dt = datetime.now() year = str(dt.year) month = str(dt.strftime("%m")) day = str(dt.day) year_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[0:4] month_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[5:7] day_doj = str( Registration.objects( patient_ssnid=ssnid).first().doj)[8:10] dod = day + "-" + month + "-" + year doj = day_doj + "-" + month_doj + "-" + year_doj details = Registration.objects(patient_ssnid=ssnid) meds_used = GiveMedicine.objects(patient_ssnid=ssnid) test = IssueDiagnostics.objects(patient_ssnid=ssnid) enter = datetime(int(year), int(month), int(day)) leave = datetime(int(year_doj), int(month_doj), int(day_doj)) calc = str(abs(leave - enter))[0:2] room_calc = int(calc) * Registration.objects( patient_ssnid=ssnid).first().room_amount flash("Patient Found", "success") return render_template('billing.html', form=form, det=details, med=meds_used, test=test, test_sum=test_sum, med_sum=med_sum, tot=test_sum + med_sum + int(room_calc), dod=dod, doj=doj, calc=calc, room_calc=room_calc) else: flash("This ID is not registered", "danger") elif request.method == "POST": if Registration.objects(patient_ssnid=ssnid): if 'confirm' in request.form: dt = datetime.now() year = str(dt.year) month = str(dt.strftime("%m")) day = str(dt.day) year_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[0:4] month_doj = str( Registration.objects(patient_ssnid=ssnid).first().doj)[5:7] day_doj = str( Registration.objects( patient_ssnid=ssnid).first().doj)[8:10] dod = day + "-" + month + "-" + year doj = day_doj + "-" + month_doj + "-" + year_doj details = Registration.objects(patient_ssnid=ssnid) meds_used = GiveMedicine.objects(patient_ssnid=ssnid) test = IssueDiagnostics.objects(patient_ssnid=ssnid) enter = datetime(int(year), int(month), int(day)) leave = datetime(int(year_doj), int(month_doj), int(day_doj)) calc = str(abs(leave - enter))[0:2] room_calc = int(calc) * Registration.objects( patient_ssnid=ssnid).first().room_amount flash("The Patient Can Be Discharged", "success") Registration.objects(patient_ssnid=ssnid).update( status="Discharged") return render_template('billing.html', form=form, det=details, med=meds_used, test=test, test_sum=test_sum, med_sum=med_sum, tot=test_sum + med_sum + int(room_calc), dod=dod, doj=doj, calc=calc, room_calc=room_calc) return render_template('billing.html', form=form, det=details, med=meds_used, test=test, test_sum=test_sum, med_sum=med_sum, tot=test_sum + med_sum + int(room_calc), dod=dod, doj=doj, calc=calc, room_calc=room_calc) #----------------------------------------------------------------------------------------------
for child in registration.children: child = Registration(**child) child.parent = registration self.process(child) annotated = open("output/2-registrations-with-renewals.ndjson", "w") cross_references = open( "output/2-cross-references-in-foreign-registrations.ndjson", "w") comparator = Comparator("output/1-parsed-renewals.ndjson") processor = Processor(comparator, annotated, cross_references) before = time.time() count = 0 for i in open("output/0-parsed-registrations.ndjson"): processor.process(Registration(**json.loads(i))) count += 1 if not count % 10000: after = time.time() print("%d %.2fsec" % (count, after - before)) before = after after = None # Now that we're done, we can divide up the renewals by whether or not # we found a registration for them. renewals_matched = open("output/2-renewals-with-registrations.ndjson", "w") renewals_not_matched = open("output/2-renewals-with-no-registrations.ndjson", "w") for regnum, renewals in comparator.renewals.items(): for renewal in renewals:
out.writerow(self.ia_data) out.writerow(self.cce_data) out.writerow([]) packages = [] for i in open("output/hathi-0-matched.ndjson"): data = json.loads(i) quality = data['quality'] if quality < cutoff: continue quality = round(quality, 2) hathi = data['hathi'] cce = Registration(**data['cce']) hathi_link = "https://catalog.hathitrust.org/Record/%s" % hathi[ 'identifier'] cce_id = cce.uuid hathi_title = hathi['title'] cce_title = cce.title hathi_author = hathi.get('author') cce_authors = cce.authors or [] for pub in cce.publishers: claimants = pub.get('claimants') if claimants: for i in claimants: if i:
def view_patient(): if not session.get('login_id'): return redirect(url_for('admin_login')) view = Registration.objects().all() return render_template("viewpatient.html", view=view)
def convert(self, input_file): self.out.writerow(Registration.csv_row_labels + Renewal.csv_row_labels) for line in open(input_file): registration = Registration.from_json(json.loads(line)) self.out.writerow(registration.csv_row)
if penalty > 0: # Beyond "a couple typoes", the Levenshtein distance # basically means there's no match, so we cap the penalty # at a pretty low level. penalty = min(penalty, 0.20) return penalty comparator = Comparator("output/ia-0-texts.ndjson") output = open("output/ia-1-matched.ndjson", "w") for filename in ["FINAL-not-renewed.ndjson" ]: #"FINAL-possibly-renewed.ndjson"]: for i in open("output/%s" % filename): cce = Registration.from_json(json.loads(i)) title = cce.title if not title or not comparator.normalize(title): continue matches = list(comparator.matches(cce)) # If there are a huge number of IA matches for a CCE title, # penalize them -- it's probably a big mess that must be dealt # with separately. Give a slight boost if there's only a single # match. if len(matches) == 1: num_matches_coefficient = 1.1 elif len(matches) <= MATCH_CUTOFF: num_matches_coefficient = 1 else: num_matches_coefficient = 1 - (len(matches) -
def process_file(self, path): tree = etree.parse(open(path), self.parser) for e in tree.xpath("//copyrightEntry"): for registration in Registration.from_tag(e, include_extra=False): yield registration.jsonable()