def updatePatient(): form = PatientUpdate() disable_fields(form, 'disable') form.updatePatient.render_kw = {'disabled': 'disabled'} if (form.getDetails.data): form.dateAdmission.data = None form.bed.data = None item = patientDetails.objects(patientId=form.patientId.data).first() if (item): form = Patient(obj=item) disable_fields(form, False) form.patientId.render_kw = {'readonly': 'readonly'} form.updatePatient.render_kw = {'disabled': False} else: flash("Patient doesnot exist", "danger") return redirect(url_for('updatePatient')) if (form.updatePatient.data): patient_id = form.patientId.data message = '' if form.validate(): item = patientDetails.objects.get(patientId=patient_id) item['patientName'] = form.patientName.data item['patientAge'] = int(form.patientAge.data) if (item['status'] == False): if (item['dateAdmission'] >= datetime.combine( form.dateAdmission.data, time())): flash( "Discharged Patient's new admission date cannot be the same or less than previous date of admission", "danger") return redirect(url_for('updatePatient')) item['status'] = True message += " Patient's status updated to active" item['dateAdmission'] = datetime.combine(form.dateAdmission.data, time()) item['state'] = form.state.data item['city'] = form.city.data item['patientAddress'] = form.patientAddress.data item['bed'] = form.bed.data item.save() updated = patientDetails.objects(patientId=patient_id).first() display_fields(form, updated) message = "Patient " + str( item['patientId']) + " updated. " + message flash(message, "success") else: print(form.validate()) flash("Sorry, something went wrong", "danger") return render_template("alterPatient.html", title="Update Patient", form=form, update=True)
def diagnostics(): session['dia_patient'] = None form = Patient() form.dateAdmission.data = None form.bed.data = None disable_fields(form, 'disable') if (form.getDetails.data): if (form.patientId.data == ''): flash("Enter patient Id ", "danger") return redirect(url_for('diagnostics')) item = patientDetails.objects(patientId=form.patientId.data).first() if (item and item['status']): form = Patient(obj=item) form.patientId.render_kw = {'readonly': 'readonly'} disable_fields(form, 'disable') all_patient_diagnosis, tbill = update_diagnosis_field( item['patientId']) return render_template("diagnostics.html", diagnostics=True, title="Diagnosis", form=form, diagnosis=all_patient_diagnosis, flag=1) else: flash("Patient doesnot exist or is discharged", "danger") return redirect(url_for('diagnostics')) if (form.issueDiagnosis.data): session['dia_patient'] = int(form.patientId.data) return redirect(url_for('issueTest')) return render_template("diagnostics.html", diagnostics=True, title="Diagnosis", form=form)
def delPatient(): form = Patient() disable_fields(form, 'disable') form.deletePatient.render_kw = {'disabled': 'disabled'} if (form.getDetails.data): form.dateAdmission.data = None form.bed.data = None item = patientDetails.objects(patientId=form.patientId.data).first() if (item): form = Patient(obj=item) disable_fields(form, 'disable') form.patientId.render_kw = {'readonly': 'readonly'} form.deletePatient.render_kw = {'disabled': False} else: flash("Patient doesnot exist", "danger") return redirect(url_for('delPatient')) if (form.deletePatient.data): item = patientDetails.objects(patientId=form.patientId.data).first() if (item): patient_id = form.patientId.data patientDetails.objects(patientId=form.patientId.data).delete() meds_already = patient_med.objects( patientId=patient_id).order_by("-medId") message = "Patient Deleted " if (meds_already): meds_already.delete() test_already = patient_test.objects( patientId=patient_id).order_by("-testId") if (test_already): test_already.delete() flash(message, "success") return redirect(url_for('delPatient')) return render_template("alterPatient.html", title="Delete Patient", form=form, delete=True)
def validate_SSNID(form, field): try: int(field.data) print(field.data) patientSSNID = patientDetails.objects(patientSSN=field.data).first() if patientSSNID: status = patientSSNID['status'] if (status): raise ValidationError("Already exists") else: raise ValidationError("Patient Exists and is discharged") except: raise ValidationError('Please enter integers only')
def searchPatient(): form = Patient() form.dateAdmission.data = None form.bed.data = None disable_fields(form, 'disable') if (form.getDetails.data): item = patientDetails.objects(patientId=form.patientId.data).first() if (item): form = Patient(obj=item) form.patientId.render_kw = {'disabled': 'disabled'} if (item['status'] == False): print("Patient has been discharged", "danger") return redirect(url_for('searchPatient')) disable_fields(form, 'disable') form.patientId.render_kw = {'readonly': 'readonly'} else: flash("Patient doesnot exist", "danger") return redirect(url_for('searchPatient')) return render_template("alterPatient.html", title="Search Patient", form=form, search=True)
def pharmacyDetails(): form = Patient() #to get patient id and display patient details form.dateAdmission.data = None form.bed.data = None disable_fields(form, 'disable') session['med_patient'] = None #---------------To display patient information--------- if (form.getDetails.data): if (form.patientId.data == ''): flash("Please enter patient Id ", "danger") return redirect(url_for('pharmacyDetails')) item = patientDetails.objects(patientId=form.patientId.data).first() if (item and item['status']): form = Patient(obj=item) form.patientId.render_kw = {'readonly': 'readonly'} disable_fields(form, 'disable') all_patient_med, mbill = update_medicines_field(item['patientId']) return render_template("pharmacy.html", pharmacy=True, title="Pharmacy", form=form, medicines=all_patient_med, flag=1) else: flash("Patient doesnot exist or is discharged", "danger") return redirect(url_for('pharmacyDetails')) if (form.issueMedicine.data): session['med_patient'] = int(form.patientId.data) return redirect(url_for('issueMed')) return render_template("pharmacy.html", pharmacy=True, title="Pharmacy", form=form)
def issueTest(): try: p_id = session['dia_patient'] dept = session['dept'] except: return redirect(url_for('diagnostics')) if (p_id == None and session['dept'] == 'diagnosis'): flash("Please enter patient id", "danger") return redirect(url_for('diagnostics')) all_patient_diagnosis, tbill = update_diagnosis_field(p_id) patient_details = patientDetails.objects(patientId=p_id).first() all_test = test_details.objects().order_by("-testId") test_list = [(i['testId'], i['testName']) for i in all_test] form_med = Test_form() #form for this page form_med.testName.choices = test_list #To pass choices to select field form_med.amount.render_kw = {'readonly': 'readonly'} if (form_med.update.data or form_med.addTest.data): if (form_med.validate_on_submit()): test = test_details.objects( testId__iexact=form_med.testName.data).first() if (test == None): flash("Test not Found ", "danger") return render_template("issueDiagnosis.html", issueDiagnosis=True, title="Issue Diagnosis", form_med=form_med, valid=1, diagnosis=all_patient_diagnosis, data=patient_details) else: ptest = patient_test(patientId=p_id, testId=test['testId']) ptest.save() #add new test to database flash("Test added", "success") if (form_med.update.data): session['dia_patient'] = None return redirect(url_for('diagnostics')) else: form_med.testName.data = None form_med.amount.data = None all_patient_diagnosis, tbill = update_diagnosis_field(p_id) return render_template("issueDiagnosis.html", diagnostics=True, title="Issue Diagnostics", form_med=form_med, valid=1, diagnosis=all_patient_diagnosis, data=patient_details) if (form_med.getRate.data): if (form_med.validate_on_submit()): obj = test_details.objects( testId__iexact=form_med.testName.data).first() print(obj) if (obj == None): flash("Test not Found ", "danger") form_med.amount.data = None return render_template("issueDiagnosis.html", issueDiagnosis=True, title="Issue Diagnosis", form_med=form_med, valid=1, diagnosis=all_patient_diagnosis, data=patient_details) else: form_med.amount.data = obj['rate'] form_med.testName.data = obj['testName'] return render_template("issueDiagnosis.html", diagnostics=True, title="Issue Diagnostics", form_med=form_med, valid=1, diagnosis=all_patient_diagnosis, data=patient_details)
def issueMed(): try: p_id = session['med_patient'] #from previous page dept = session['dept'] except: return redirect(url_for('pharmacyDetails')) if (p_id == None and session['dept'] == 'pharmacy'): flash("Please enter patient id", "danger") return redirect(url_for('pharmacyDetails')) all_patient_med, mbill = update_medicines_field(p_id) patient_details = patientDetails.objects(patientId=p_id).first() form_med = Medicine_form() form_med.medicineRate.render_kw = {'readonly': 'readonly'} form_med.medicineAmount.render_kw = {'readonly': 'readonly'} if (form_med.update.data or form_med.addMedicine.data): if (form_med.validate_on_submit()): med = medicine_details.objects( medName__icontains=form_med.medicineName.data).first() if (med == None): flash("Out of stock", "danger") return render_template("issueMed.html", pharmacy=True, title="Pharmacy", form_med=form_med, valid=1, medicines=all_patient_med, data=patient_details) else: qty = int(form_med.medicineQty.data) if (qty > med['qty']): message = "Only " + str( med['qty']) + " medicines available for " + str( med['medName']) flash(message, "danger") else: med['qty'] -= qty med.save() #update medicine database #update patient-medicine database if (patient_med.objects(patientId=p_id, medId=med['medId']).first()): item = patient_med.objects(patientId=p_id, medId=med['medId']).first() item['pmed_qty'] += qty item.save() else: pmed = patient_med(patientId=p_id, medId=med['medId'], pmed_qty=qty) pmed.save() flash("Medicine added", "success") if (form_med.update.data): session['med_patient'] = None return redirect(url_for('pharmacyDetails')) else: all_patient_med, mbill = update_medicines_field(p_id) form_med.medicineQty.data = None form_med.medicineName.data = None form_med.medicineRate.data = None form_med.medicineAmount.data = None return render_template("issueMed.html", pharmacy=True, title="Issue Medicine", form_med=form_med, valid=1, medicines=all_patient_med, data=patient_details) if (form_med.getRate.data): if (form_med.validate_on_submit()): med = medicine_details.objects( medName__icontains=form_med.medicineName.data).first() if (med == None): flash("Out of stock", "danger") return render_template("issueMed.html", pharmacy=True, title="Pharmacy", form_med=form_med, valid=1, medicines=all_patient_med, data=patient_details) else: qty = int(form_med.medicineQty.data) if (qty > med['qty']): message = "Only " + str( med['qty']) + " medicines available for " + str( med['medName']) flash(message, "danger") else: form_med.medicineRate.data = med['rate'] form_med.medicineAmount.data = med.get_cost(qty) form_med.medicineName.data = med['medName'] return render_template("issueMed.html", pharmacy=True, title="Issue Medicine", form_med=form_med, valid=1, medicines=all_patient_med, data=patient_details)
def patientbill(): form = Patient() #to get patient id and display patient details form.dateAdmission.data = None form.bed.data = None disable_fields(form, 'disable') datenow = datetime.now().isoformat() #-----------------------------To display all bill information---------------------------- if (form.getDetails.data): if (form.patientId.data == ''): flash("Enter patient Id ", "danger") return redirect(url_for('patientBill')) item = patientDetails.objects(patientId=form.patientId.data).first() if (item): if (item['status'] == False): flash("Patient has been discharged", "danger") return redirect(url_for('patientbill')) form = Patient(obj=item) form.patientId.render_kw = {'readonly': 'readonly'} disable_fields(form, 'disable') all_patient_med, mbill = update_medicines_field(item['patientId']) all_patient_diagnosis, tbill = update_diagnosis_field( item['patientId']) room = get_room_cost(item) totalCost = room['cost'] + mbill + tbill return render_template("patientBill.html", patientBill=True, title="Patient Bill", form=form, medicines=all_patient_med, diagnosis=all_patient_diagnosis, flag=1, room=room, mbill=mbill, tbill=tbill, totalCost=totalCost, datenow=datenow) else: flash("Patient not found", "danger") return redirect(url_for('patientbill')) #---------update status of patient ------------- if (form.getBill.data): if (is_pid(form.patientId.data)): item = patientDetails.objects( patientId=form.patientId.data).first() if (item['status'] == False): message = "Patient with id :" + str( item['patientId']) + ' has checked out already.' flash(message, "danger") return render_template("patientBill.html", patientBill=True, title="Patient Bill", form=form, flag=0, datenow=datenow) item['status'] = False item.save() pmed = patient_med.objects(patientId=form.patientId.data, paid=False).update(set__paid=True) ptest = patient_test.objects(patientId=form.patientId.data, paid=False).update(set__paid=True) print(ptest) message = "Patient with id : " + str( item['patientId']) + ' is now discharged.' flash(message, "success") return render_template("patientBill.html", patientBill=True, title="Patient Bill", form=form, flag=0, datenow=datenow) return render_template("patientBill.html", patientBill=True, title="Patient Bill", form=form, flag=0, datenow=datenow)
def viewAll(): all_patients = patientDetails.objects(status=True).order_by("-patientId") return render_template("viewAll.html", all_patients=all_patients, viewAll=True, title="View All Patients")